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.
I hit a similar problem with the new weak type checking:
https://github.com/Microsoft/TypeScript/issues/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.
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.
Have you tried exclude in your tsconfig.json?
exclude does not work for type definitions. For example: exclude: ["node_modules"] still contains all type definitions of all installed dependencies.
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.
Have you tried path mapping (https://www.typescriptlang.org/docs/handbook/module-resolution.html) to map that path to a non-existant one?
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)
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
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"]
}
Hi @RyanCavanaugh ,
I tried this , but it seems cannot disable those global declaration.
Such as @type/node
@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.
@jraoult @RyanCavanaugh
Well, so paths can disable a specific type, but it seems cannot do that to global declaration.
Like @types/node ...
for global declarations set "types" : [] this will not load any packages from @types. you can add ones you want e.g. "types": ["node"]
@mhegazy
Should I add all types one by one only for excluding specific one?
Maybe better if it is like include and exclude ?
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.