Skip to content

/// <reference types="xxx" /> from packages introduce collisions #12040

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

Closed
tomitrescak opened this issue Nov 4, 2016 · 7 comments
Closed

/// <reference types="xxx" /> from packages introduce collisions #12040

tomitrescak opened this issue Nov 4, 2016 · 7 comments
Labels
Needs More Info The issue still hasn't been fully clarified @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped

Comments

@tomitrescak
Copy link

tomitrescak commented Nov 4, 2016

TypeScript Version: nightly (2.1.0-dev.201xxxxx)

The problem here is related to #11671

  1. Package that I use requires "es6-shim" as following /// <reference types="es6-shim" />.

  2. This REQUIRES me to install @types/es6-shim otherwise I get an error

  3. My project is ES6 based. As a result, after I install that dependency, I get following error during compilation:

     file: 'file:///Users/tomi/Github/apps/Clara-Apollo/node_modules/%40types/es6-shim/index.d.ts'
     severity: 'Error' 
     message: 'Duplicate identifier 'PropertyKey'.'
    
  4. No matter what I set to types property or to typeRoots the error will never go away, unless I manually delete the 'PropertyKey' definition in the es6-shim.d.ts file. While this is ok in local, it PROHIBITS CI, as the project will never compile on CI server

What can I do in this case? Is there any way I can protect myself from these errors?

@tomitrescak
Copy link
Author

tomitrescak commented Nov 4, 2016

What I tried was to set typeRoots to another directory where I kept that modified 'es6-shim.d.ts' with removed PropertyKey, but compiler is persistent that I have to have es6-shim.d.ts in @types directory.

What I also tried was to set types to only interesting types such as ['React']

@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2016

Package that I use requires "es6-shim" as following /// .

why? is it a hard dependency on es6-shims? looks to me that this is not the case, as you can use the library without es6-shims. so the fix would be to remove this dependency declaration from you other package. feel free to send a PR to DefinitelyTyped, and i will get it in.

removed PropertyKey, but compiler is persistent that I have to have es6-shim.d.ts in @types directory.

how so? can you share more details.

What I also tried was to set types to only interesting types such as ['React']

This is a dependency of your other package. it needs to be satisfied to make it work.

@tomitrescak tomitrescak added Needs More Info The issue still hasn't been fully clarified @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped labels Nov 7, 2016
@tomitrescak
Copy link
Author

tomitrescak commented Nov 7, 2016

The package name is the popular react-apollo that brings graphql support and is built with typescript. What happens is that the package is built with "definitions". And definitions have the /// <reference types="es6-shim" /> automatically added by typescript compiler.

This is how one of the .d.ts files looks like:

/// <reference types="react" />
/// <reference types="chai" />
/// <reference types="typed-graphql" />
/// <reference types="node" />
/// <reference types="es6-shim" />
import * as React from 'react';
....

I have not found any way of fighting back against this, only manually removing the "shim" reference in my node_modules, but as you can imagine this is not possible in CI.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2016

And definitions have the /// automatically added by typescript compiler.

This should be fixed in #11872 (see #11849)

@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2016

I have not found any way of fighting back against this, only manually removing the "shim" reference in my node_modules, but as you can imagine this is not possible in CI.

you should be able to override any declaration package using typeRoots. e..g create a new empty file overrideTypings\es6-shims\index.d.ts, then set typeRoots to be ["overrideTypeings", "node_modules\@types"].

@tomitrescak
Copy link
Author

@mhegazy thanks for your help! It took me awhile to realise how complete answer you gave me, as I have initially created my file as overrideTypings/es6-shim.d.ts not overrideTypings/es6-shim/index.d.ts. With a little help from --traceResolution flag I realised what my problem was.

THANKS! 🌹

@mhegazy
Copy link
Contributor

mhegazy commented Nov 8, 2016

Glad this was resolved. but i want to emphasize that the main issue here is on the package side (caused by a compiler bug). Overriding declaration packages, though possible, is not the best possible solution.

@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
Needs More Info The issue still hasn't been fully clarified @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped
Projects
None yet
Development

No branches or pull requests

2 participants