Skip to content

Can't disable type definitions for one special library #17042

Description

TypeScript Version: 2.4.1

For example I want to consume a library from npm called awesome-lib. This library already ships with a TypeScript type definition but this one is outdated and buggy. The author of the library doesn't update this one.

I've tried to disable that type definition completely in my own declarations.d.ts file in my project:

declare module 'awesome-lib';

Unfortunately TypeScript reads first the type definition in the library and throws some errors. So it is not possible for me to disable / hide this library for my project.

Activity

  1. smhc commented on Jul 9, 2017

    @smhc

    I hit a similar problem with the new weak type checking:
    #16968

    The more strict checks are fine for code you have control over, but for third party libs it is a problem. Even if the author updates, the newer version may have breaking changes.

    Theoretically each third party dependency should be compiled using the compiler version specified by it, however this is impractical. A way to disable these type checks on a per library basis may be more realistic.

  2. screendriver commented on Jul 10, 2017

    @screendriver
    Author

    The best solution would be the opposite of "types" in the compiler options in the compiler options. types is exactly what I want but in the other direction: I want to exclude some type definitions.

  3. kitsonk commented on Jul 10, 2017

    @kitsonk
    Contributor

    Have you tried exclude in your tsconfig.json?

  4. screendriver commented on Jul 10, 2017

    @screendriver
    Author

    exclude does not work for type definitions. For example: exclude: ["node_modules"] still contains all type definitions of all installed dependencies.

  5. jraoult commented on Jul 24, 2017

    @jraoult

    This option would be awesome to avoid transitive definition files to "pollute" the "ambient" space. My case, for example, I want react-modal types but not the react it imports.

  6. RyanCavanaugh commented on Jul 25, 2017

    @RyanCavanaugh
    Member

    Have you tried path mapping (https://www.typescriptlang.org/docs/handbook/module-resolution.html) to map that path to a non-existant one?

  7. jraoult commented on Jul 25, 2017

    @jraoult

    Thanks Ryan Cavanaugh (@RyanCavanaugh) it worked indeed, nice workaround. Small gotcha, I had to make sure the file actually existed (I first tried with a fake file name)

  8. mhegazy commented on Sep 5, 2017

    @mhegazy
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  9. k8w commented on Sep 7, 2017

    @k8w

    Hi, Jonathan Raoult (@jraoult) .
    Can you share your tsconfig.json ?

    I tried this but failed:

    "paths": {
        "node_modules/@types/node" : ["NOT_EXISTS"],
        "@types/node" : ["NOT_EXISTS"],
        "node" : ["NOT_EXISTS"]
    }
    
  10. k8w commented on Sep 7, 2017

    @k8w

    Hi Ryan Cavanaugh (@RyanCavanaugh) ,
    I tried this , but it seems cannot disable those global declaration.
    Such as @type/node

  11. jraoult commented on Sep 7, 2017

    @jraoult

    Zhongyang Wang (@k8w) sure thing

     "paths": {
          "react": [
            ".sink.d.ts"
          ],
          "inferno-mobx": [
            ".sink.d.ts"
          ]
        }
    

    So as I mentioned earlier you actually need the file (.sink.d.ts in this case) to exist.

  12. k8w commented on Sep 8, 2017

    @k8w

    Jonathan Raoult (@jraoult) Ryan Cavanaugh (@RyanCavanaugh)
    Well, so paths can disable a specific type, but it seems cannot do that to global declaration.
    Like @types/node ...

  13. mhegazy commented on Sep 11, 2017

    @mhegazy
    Contributor

    for global declarations set "types" : [] this will not load any packages from @types. you can add ones you want e.g. "types": ["node"]

  14. k8w commented on Sep 12, 2017

    @k8w

    Mohamed Hegazy (@mhegazy)
    Should I add all types one by one only for excluding specific one?
    Maybe better if it is like include and exclude ?

  15. screendriver commented on Sep 12, 2017

    @screendriver
    Author

    for global declarations set "types" : [] this will not load any packages from Types (@types). you can add ones you want e.g. "types": ["node"]

    Mohamed Hegazy (@mhegazy) but that's not what I want as I said before.

  16. locked and limited conversation to collaborators on Jun 14, 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

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions