create-react-app typescript global.d.ts file doesn't work
Provided your .d.ts
file doesn't import or export anything, you can omit the declare global
block.
You will need to make sure this file is either in an @types
directory, or that you have configured your typeRoots
to include the directory for your type declarations e.g.
{
"compilerOptions": {
"typeRoots": [
"./node_modules/@types/",
"./custom/path/to/declarations/"
]
}
}
Some more info about this can be found here.
A simpler approach would be to export an empty object from your global.d.ts
, like so:
declare global {
interface Window {
config: {
url: string;
};
}
}
// Adding this exports the declaration file which Typescript/CRA can now pickup:
export {}