-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Using /// <reference lib="dom" /> in a .d.ts typescript declaration file has global effects #33901
Comments
This is what a lib reference does. |
Ah ok, so lib references also have this behaviour for all files in the compilation, not only the d.ts files. After reading the documentation another time I found the description: We have found this is an issue, because we had a node typescript project that uses superagent/supertest. During refactoring an import to our own "Element" method got dropped, which however didn't cause the compilation to fail. Instead it caused a seperate project to fail compilation, because types didn't match. (Local testcases would have probably caught this issue). Is there a way to make sure that no package may change our compilation settings? (other than manually checking every file and after every update) |
Do you think that splitting @types packages like the one for superagent into multiple packages depending on intended usage environment is a viable option? |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@RyanCavanaugh Should type directives be confined to the project they're imported by? For example, let's say I have a The problem is that Storybook uses a type directive, and it leaks into my React Native modules, despite them never importing Storybook. I've made sure the |
Is there a workaround for this from the point of view of the library user? |
@LilRed There's no workaround until the |
TypeScript Version: 3.5.3, 3.6.3
Search Terms:
Code
arbitrary.d.ts
/// <reference lib="dom" />
index.ts
Expected behavior:
Executing
npx tsc --noEmit --target esnext --lib esnext index.ts
should produce a compile error because Element is not defined nor imported and lib dom is not set globally.The documentation for triple slash directives states the following:
https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html
For declaration file authors who rely on built-in types, e.g. DOM APIs or built-in JS run-time constructors like Symbol or Iterable, triple-slash-reference lib directives are recommended. Previously these .d.ts files had to add forward/duplicate declarations of such types.
used in e.g. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/superagent/index.d.ts
Actual behavior:
It just compiles.
Related Issues:
The text was updated successfully, but these errors were encountered: