This is my code:
tsconfig.js
{
"compilerOptions": {
"baseUrl": "./",
"target": "es6",
"module": "commonjs",
"declaration": true,
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"typeRoots": [
"node_modules/@types",
"./@types"
],
"paths": {
"@types/*": ["@types/*"]
},
},
"exclude": ["node_modules"],
"include": ["./*", "@types"]
}
@types/index.d.ts
interface Person {
is: boolean;
str: string;
}
type doThing = (is: boolean) => boolean;
example.ts
const jon: Person = {
is: 'hello world'
}
const doThing = x => `${x}`;
in example.js:
- The interface for 'Person' is found and works
- The type for 'doThing' is not found
It seems the only sure way is to create a type which is named differently, but can be used onto any function.
index.d.ts
example.d.ts