镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

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?

Activity

  1. tomitrescak commented on Nov 4, 2016

    @tomitrescak
    Author

    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 (@types) directory.

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

  2. mhegazy commented on Nov 7, 2016

    @mhegazy
    Contributor

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

  3. added
    Needs More InfoThe issue still hasn't been fully clarified
    @typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTyped
    on Nov 7, 2016
  4. tomitrescak commented on Nov 7, 2016

    @tomitrescak
    Author

    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.

  5. mhegazy commented on Nov 7, 2016

    @mhegazy
    Contributor

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

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

  6. mhegazy commented on Nov 7, 2016

    @mhegazy
    Contributor

    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"].

  7. tomitrescak commented on Nov 8, 2016

    @tomitrescak
    Author

    Mohamed Hegazy (@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! 🌹

  8. mhegazy commented on Nov 8, 2016

    @mhegazy
    Contributor

    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.

  9. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    @typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedNeeds More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions