I'm setting up TypeScript in an existing JS project, and I'm trying to figure out how to add typings to an untyped npm module, since I know it'll come up.
This line
import X from 'foo';
errors out with Cannot find module 'foo'
In typings/modules I have a foo folder with an index.d.ts file therein with
declare module foo {
export default class XXX{
}
}
In the parent typings/index.d.ts I've added
/// <reference path="modules/foo/index.d.ts" />
But still nothing.
My tsconfig.json file looks like this
{
"compilerOptions": {
"target": "esnext",
"baseUrl": "./src",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"allowJs": true,
"moduleResolution": "node",
"module": "es2015",
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"typeRoots" : ["./typings/modules", "./node_modules/@types"]
},
"include": [
"./src/**/*.ts",
"./src/**/*.tsx"
]
}