I'm testing out how the TS compiler resolves ambient declarations for local files. I can't seem to find a way to tell it to look for type files if I put them anywhere other than right beside the source js files. Here's a demo. For example:
// src/templates/Hello.d.ts
declare function Hello(): string;
export default Hello;
// src/index.ts
import Hello from './templates/Hello.js'; // can't find declarations UNLESS Hello.d.ts is colocated.
Hello();
// tsconfig.json
{
"compilerOptions": {
"skipLibCheck": true,
"noEmit": true
},
"include": ["src"]
}
What I'd like to do is to put the Hello.d.ts
file in ./src/types/Hello.d.ts
. I've tried various things like using baseUrl
and paths
in tsconfig.json
, triple slash directives, using declare module
(but I can't seem to use relative paths to point to the specific file I'm trying to create types for), but so far no luck.