Closed RyanNerd closed 4 years ago
Check out the TypeScript support section of the README. 🙂
Thanks @CharlesStover but I did create a src/global.d.ts
file per the instructions in the README and I'm still needing to use // @ts-ignore
to get this to compile. Any ideas why this is not working?
Do you have a custom tsconfig.json
file?
@CharlesStover Thanks for your help with this. This is what my tsconfig.json
looks like:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
I am fairly certain that TypeScript does not support global.d.ts
files when compilerOptions.isolatedModules
is set to true
.
Additionally, in a recent project I had to set compilerOptions.baseUrl
to "src"
.
If you find that global.d.ts
is incompatible with your project (due to a need for isolatedModules
), I'd recommend moving the global state to a Provider, then import the Provider and use its Provider.useGlobal
method instead of the default global state.
One way around the limitations of the isolatedModules
call for me was to create a reactn.d.ts
file in a styles
folder and put the stuff from the README in there.
src/
- ...
- types/
- reactn.d.ts
- index.d.ts
That seems to load everything correctly, and typecheck appropriately.
I need to use
@ts-ignore
to get this to compile