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

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

Closed
screendriver opened this issue Jul 9, 2017 · 15 comments
Closed

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

screendriver opened this issue Jul 9, 2017 · 15 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@screendriver
Copy link

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.

@smhc
Copy link

smhc commented Jul 9, 2017

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.

@screendriver
Copy link
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.

@kitsonk
Copy link
Contributor

kitsonk commented Jul 10, 2017

Have you tried exclude in your tsconfig.json?

@screendriver
Copy link
Author

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

@jraoult
Copy link

jraoult commented Jul 24, 2017

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.

@RyanCavanaugh
Copy link
Member

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

@jraoult
Copy link

jraoult commented Jul 25, 2017

Thanks @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)

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Aug 21, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 5, 2017

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

@mhegazy mhegazy closed this as completed Sep 5, 2017
@k8w
Copy link

k8w commented Sep 7, 2017

Hi, @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"]
}

@k8w
Copy link

k8w commented Sep 7, 2017

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

@jraoult
Copy link

jraoult commented Sep 7, 2017

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

@k8w
Copy link

k8w commented Sep 8, 2017

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

@mhegazy
Copy link
Contributor

mhegazy commented Sep 11, 2017

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

@k8w
Copy link

k8w commented Sep 12, 2017

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

@screendriver
Copy link
Author

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

@mhegazy but that's not what I want as I said before.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

7 participants