-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptcheckJsRelates to checking JavaScript using TypeScriptRelates to checking JavaScript using TypeScript
Milestone
Description
TypeScript Version: >= 3.9
The problem doesn't occur when compiling with 3.8.* or 3.9.0-beta, but all other versions of 3.9, 4.0 and 4.1 reproduce the issue.
Search Terms: duplicate identifier
Code
a.js
/** @type {import('./types').Config} */
const data = JSON.parse('');
data.uploads = {};
module.exports = data;
types.d.ts
export interface Config {
uploads: {
}
}
tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"checkJs": true
},
"include": [ "*.js", "*.ts" ]
}
Run tsc
Expected behavior: Code compiles without errors
Actual behavior:
a.js:3:1 - error TS2300: Duplicate identifier 'uploads'.
data.uploads = {};
~~~~~~~~~~~~
types.d.ts:2:5
uploads: {
~~~~~~~
'uploads' was also declared here.
Found 1 error.
Workarounds:
Specifying type of module.exports
like the following:
a.js
/** @type {import('./types').Config} */
const data = JSON.parse('');
data.uploads = {};
/** @type {import('./types').Config} */
module.exports = data;
Exporting data
differently:
module.exports = { data };
Changing the file extension of a.js
to ts
(however, this not an option for us, we are only using tsc for type checking)
FINDarksideandrewbranch
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptcheckJsRelates to checking JavaScript using TypeScriptRelates to checking JavaScript using TypeScript