By utilizing VSCode, it is nearly achievable to leverage the advantages of Typescript in plain .js
files through jsDoc notation and a tsconfig.json
configuration:
{
"compileOnSave": false,
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"checkJs": true,
"target": "es6",
"resolveJsonModule": true,
"moduleResolution": "node",
},
"include": ["index.js", "./src"]
}
/**
* @return {Promise<string>}
*/
const foo = Promise.resolve('hi');
module.exports = foo;
Now, is it viable to access an interface specified in a d.ts
file within the node_modules
directory? Specifically, I'm trying to return a -let's say- "my_dependency.Storage" object but facing difficulty referencing it using regular javascript:
/**
* @param {Storage} storage
*/
const goo = storage => ...
This function will recognize that I am referring to the Web Storage API from lib.dom.d.ts
- The equivalent typescript statement would be:
import {Storage} from "my_dependency"
- I have attempted to use triple slash directives without success
///<reference path="node_modules/my_dependency/lib/index.d.ts" />
- I am hoping for something like (pseudo-code)
/**
* @param {my_module.Storage} storage
*/