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

For ES2015 target, cannot exclude conflicting @types of dependencies with ES5 target #12814

Closed
cgilboy opened this issue Dec 9, 2016 · 3 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@cgilboy
Copy link

cgilboy commented Dec 9, 2016

My project has an external dependency that was written in Typescript, targets ES5 and depends on @types/es6-promise. I do not see a way to compile my project without tsc including node_modules/@types/es6-promise which conflicts with lib.es6.d.ts and throws type errors.

Am I missing a tsconfig.json option?

TypeScript Version: Version 2.1.4

Code
Here is a stripped down example:

tsconfig.json

{
    "compilerOptions": {
        "target": "ES2015",
        "types": []
    },
    "include": ["src/**/*"],
    "exclude": ["node_modules"]
}

index.ts

import * as dep from 'dependency';
...

Some external dependency transpiled into ES5 but depending on ES6 promise - dependency.d.ts

/// <reference types="es6-promise" />
export declare function usesPromises();

Expected behavior:
No type errors.

Actual behavior:

node_modules/typescript/lib/lib.es6.d.ts(5261,11): error TS2300: Duplicate identifier 'Promise'.
node_modules/typescript/lib/lib.es6.d.ts(5511,13): error TS2300: Duplicate identifier 'Promise'.
node_modules/typescript/lib/lib.es6.d.ts(5737,11): error TS2300: Duplicate identifier 'Promise'.
node_modules/@types/es6-promise/index.d.ts(11,15): error TS2300: Duplicate identifier 'Promise'.
node_modules/@types/es6-promise/index.d.ts(42,19): error TS2300: Duplicate identifier 'Promise'.
@cgilboy
Copy link
Author

cgilboy commented Dec 10, 2016

Here is a quick repro project:
https://github.com/cgilboy/typescript_issue_12814

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Dec 10, 2016

Since fake.d.ts references es6-promise as a global, but is itself a module, it is polluting the compilation context. Although you set "types": [], importing './fake' brings it back into view. Ideally you should submit a PR to the maintainer's of fake or fake's declaraction, depending on how it is distributed, that would update their declaration to import es6-promise correctly. That said, the current behavior is not good.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 27, 2017

The correct fix here is for your dependency to not depend on es6-promise.

@mhegazy mhegazy added the External Relates to another program, environment, or user action which we cannot control. label Apr 27, 2017
@mhegazy mhegazy closed this as completed Apr 27, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants