- Error
- Reported by the type checker
TS2403
Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'.
The same var or declared variable is declared again with a different type. Use one type for every declaration, or rename one of them.
What it means
var declarations, and variables merged from several declaration files, all declare the same variable. Each declaration must state the same type; a later one with a different type is reported.
Example
export {};
var limit: number;
var limit: string;
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(3,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'limit' must be of type 'number', but here has type 'string'.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Give every declaration of the variable the same type.
- Rename one of them if they are really different variables.
- Use
letorconst, which can't be redeclared at all, for new code.