I'm currently importing a large search index (43MB) via
// sample.ts
import index from './index.json';
// ...
TS server skips the file for being too large, which types index as {}. This results in errors such as Property 'xyz' does not exist on type '{}'. ts(2339).
That behavior is reasonable to me, but providing a declaration file (index.d.ts) for this import doesn't appear to workaround this. index remains {}.
// index.d.ts
declare module "*.json" {
const value: {
xyz: {
[key: string]: number;
}
}
export default value;
}
Q: Are declaration files used/supported for JSON imports? (I can't get them to have any effect small or large! I've verified TS server is finding/loading them.)
Q: Is there an alternate approach I should take here with regards to loading large JSON files?
Some meta information:
- Started with create-react-app
- App generally compiles and works (without strict mode)
- tsconfig.json snippet:
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",