Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate identifier error caused by lib.dom.d.ts #35578

Closed
SkeLLLa opened this issue Dec 9, 2019 · 15 comments
Closed

Duplicate identifier error caused by lib.dom.d.ts #35578

SkeLLLa opened this issue Dec 9, 2019 · 15 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@SkeLLLa
Copy link

SkeLLLa commented Dec 9, 2019

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: #20595 #5585 #4168 DefinitelyTyped/DefinitelyTyped#34960

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Dec 9, 2019
@RyanCavanaugh
Copy link
Member

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.

@SkeLLLa
Copy link
Author

SkeLLLa commented Dec 9, 2019

@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.

@fatcerberus
Copy link

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?

@SkeLLLa
Copy link
Author

SkeLLLa commented Dec 10, 2019

@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.

@typescript-bot
Copy link
Collaborator

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.

@SkeLLLa
Copy link
Author

SkeLLLa commented Dec 15, 2019

It's not a question. It's a bug. @RyanCavanaugh

@viggyfresh
Copy link

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?

@SkeLLLa
Copy link
Author

SkeLLLa commented Jan 20, 2020

@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

@viggyfresh
Copy link

Right after I posted this, had a breakthrough - the /// <reference syntax uses “dom” as the lib text, not lib.dom.d.ts. For posterity, if you are mysteriously including lib.dom.d.ts, search your node modules for a package that contains that reference...you might be surprised.

@SkeLLLa
Copy link
Author

SkeLLLa commented Jan 20, 2020

@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.

@hansgfixed
Copy link

Anything new on this? Facing the exact same issue.

@SkeLLLa
Copy link
Author

SkeLLLa commented Apr 22, 2020

@hansgfixed there's just a workaround, and you need to create your own class for URL with name like myTSURLWorkaround and use it.

@nvegater
Copy link

nvegater commented Jul 3, 2020

Any news on how to fix this?

@bluenote10
Copy link

@viggyfresh Thanks for pointing that out -- has helped to narrow down the problem.

Any news on how to fix this?

I've posted a follow up issue here

@TomJerry56
Copy link

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.
With [email protected], Without adding "lib":["dom'] it is throwing error to include dom in lib but on adding lib option in tsconfig is actually causing d.ts errors in my case. Any comments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

9 participants