TypeScript Version: 3.7.3 & 3.8.0-dev.20191207
Search Terms:
Duplicate identifier, lib.dom.d.ts
Code
/// <reference types="node" />
declare global {
class URL {
hash: string;
host: string;
hostname: string;
href: string;
password: string;
pathname: string;
}
}
{
"compilerOptions": {
"target": "ESNEXT",
"module": "commonjs",
"allowJs": true,
"checkJs": true,
"strict": true,
"noImplicitAny": true,
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true
},
"files": ["./index.d.ts"]
}
Actually I've tried various tsconfig options, including target es6, with
"exclude": [
"node_modules",
"node_modules/typescript/lib/lib.dom.d.ts"
]
but nothing helped.
Expected behavior:
No error during compilation should be thrown. Or at list it should respect tsconfig exclude section and not use that lib.dom.d.ts if it's excluded.
Actual behavior:
node_modules/typescript/lib/lib.dom.d.ts:16073:11 - error TS2300: Duplicate identifier 'URL'.
Related Issues: https://github.com/microsoft/TypeScript/issues/20595 https://github.com/Microsoft/TypeScript/issues/5585 https://github.com/microsoft/TypeScript/issues/4168 https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34960
You need to set the lib setting in your tsconfig to exclude DOM typings. exclude only acts as a filter on include; this is the intended behavior.
@RyanCavanaugh what should I put to lib? I've tried es6, esnext and other values. Seems it's a possibility only to add libraries, but not exclude.
Here are some combinations that I've tried, but without any success:
"target": "ES2019",
"lib": ["ES2019"],
///
"target": "ES6",
"lib": ["ES6"],
///
"target": "ES2019",
"lib": ["ES6"],
///
"lib": ["ES2019"],
///
"target": "ES2019",
"lib": [],
///
"lib": [],
///
"target": "ES3",
"lib": ["ES2019"],
So I didn't find any way to exclude it. Seems lib option works only if you want to add something, but not exclude.
If your tsconfig has a lib field, then TypeScript should only use those--the automatic defaults don't apply. It's possible you have a <reference> somewhere in your project that directly or indirectly pulls in dom?
@fatcerberus No, there are no references to dom. The only reference is to node, but I've added it in order to check if it helps or not.
Moreover I've tested that with only one declaration file so there should be no hidden side-effects from modules or something.
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.
It's not a question. It's a bug. @RyanCavanaugh
I'm coming across this same issue and am totally stumped - I've literally grep-ed the relevant node_modules folders for references to lib.dom.d.ts but _cannot_ get it to stop interfering with typechecks. @SkeLLLa were you able to figure this out?
@viggyfresh It's a typescript bug, so there's only one option - to define something MyURL class or interface and use it unless someone will fix this one.
cc @RyanCavanaugh
Right after I posted this, had a breakthrough - the ///
@viggyfresh, yes, that's true. But according to typescript docs it shouldn't use 'dom' library unless there are something except it is set in lib section of tsconfig file. However we have what we have.
Probably you should post another issue describing what you've found. Maybe then it will get more attention.
Anything new on this? Facing the exact same issue.
@hansgfixed there's just a workaround, and you need to create your own class for URL with name like myTSURLWorkaround and use it.
Any news on how to fix this?
Most helpful comment
Any news on how to fix this?