VSCode Version: 1.20.0
First, what I think I know about Visual Studios Code IntelliSense:
- The presence of a
tsconfig.json/jsconfig.jsonshould indicate to vscode that the directory is a TypeScript/JavaScript project (docs). This means that IntelliSense should be aware of all.jsand.tsfiles in the directory (respecting theincludeandexcludeconfig properties), and all classes/definitions exported by those files without having to explicitly reference them. - In any case, you can make IntelliSense aware of classes/definitions exported by a file by explicitly referencing said file. This can be done via
require(),import, or/// <reference path="..." />. - You can mix TypeScript and JavaScript files.
Given these preconceptions, I can not get vscode to work as expected. See the simple example project below. The objective is to be able to use the Person class definition defined in test.d.ts typed definition TypeScript file in the test.js JavaScript file. However, IntelliSense complains that it is unaware of the Person class:
Note that IntelliSense works with packages that have been npm install-ed.
Given assumption #1, simply including the tsconfig.json file should be all I need. Even so, I also tried explicitly listing typings/test.d.ts and test.js in includes. I also tried listing typings in compilerOptions.typeRoots.
Given assumption #2, including a triple-slash reference directive in test.js to ./typings/test.d.ts should work.
There is a lot of outdated information out there because vscode has changed the way it handles configurations, typings, etc. I have read everything I could find but I can't get it to work.
Any ideas? What am I missing here?
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6"],
"allowJs": true,
"checkJs": true
},
"exclude": [
"node_modules"
]
}
test.js
/// <reference path="./typings/index.d.ts" />
/** @type {Person} */
const p = {};
typings/test.d.ts
export class Person {
name: string;
age: number;
}

export classtodeclare classexports but notdeclares. Here is an example.export classand import it where it needed:import {Person} from "./typings/test";require())? Can'trequire()a TypeScript file.