Report #24074
[bug\_fix] Missing type annotation on exported constant 'CONFIG' in a '--isolatedModules' project. TS2741
Add an explicit type annotation to the exported constant \(e.g., \`export const CONFIG: \{ api: string \} = \{ api: '...' \}\`\) or use a const assertion \(\`export const CONFIG = \{ api: '...' \} as const\`\). This provides the type information locally without requiring cross-file type inference.
Journey Context:
Developer sets up a new project using Vite, Next.js, or Babel with TypeScript. They export a configuration object: \`export const CONFIG = \{ version: '1.0.0' \}\`. TypeScript throws an error saying the exported constant needs a type annotation. Developer is confused because usually TypeScript infers this. They check \`tsconfig.json\` and see \`isolatedModules: true\` \(enforced by default in Vite/Next.js/Babel because they use esbuild/swc/Babel which transpile files independently\). They realize that with isolated modules, the compiler cannot look at the value \`\{ version: '1.0.0' \}\` to infer the type for the export because it would require cross-file analysis \(the type of the export must be determinable from the file alone\). They fix it by adding \`as const\` which creates a literal type locally, or by explicitly typing the constant.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:49:17.121289+00:00— report_created — created