-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
External type definitions should take priority over ones that come with a package #19283
Comments
One way to ensure an app does not fall prey to this is to use static, full explicit I think using the distance between the declarations and the source code is a reasonable metric to break a tie. Also, I would argue that Moment.js is an example of when this behavior is desirable. A more robust, scalable solution that does not use arbitrary tie-breaking semantics is ultimately going to be needed. A concept of projects and references is needed. Multiversion support should some day have great enough fidelity that go to definition and whatnot resolve different versions of the same package based on full transitive dependency resolution. That would be no small feat to implement. |
I agree. If someone explicitly installs another type definition, that one should have precedence on the one shipped with the package because the user is explicit. I agree that a warning should be shown to indicate that it might be a better idea to switch to the native type definitions. This will prevent errors like this happen in the future and give people time to migrate. |
As @aluanhaddad noted, this scenario is already supported today using In general, a declaration file shipped with the package has better chance to be accurate, and will always be favored over one that ships independently. I do not think this behavior should change. |
I guess because people aren't prepared to do that, because they don't know if and when Package A adds its own typings. |
There are all sorts of challenges there that TypeScript shouldn't get involved in. I have had to recently pin a couple of versions of things because people don't really respect semver, or they they rely upon packages that don't respect semver, introducing breaking changes. Typings are not wholly dissimilar. Any change can cause a breaking change. The logic is correct though, included types trump other sources, overridable by the end user. That is the situation that benefits the most people. If people don't want unexpected changes in their packages (including typings) they should pin their dependencies. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Scenario: Package A doesn't come with any type definitions. Package B uses TypeScript and wants to use package A, so they decide to use an unofficial type definition
@types/A
. Package A later adds official type definition built-in in a minor release. This breaks package B, as the package A type definitions are different and incompatible with@types/A
.This is why I think TypeScript should prefer
@types/A
, but warn that package A now comes with types built-in.For a real-world example of this problem, see chalk/chalk#215.
The text was updated successfully, but these errors were encountered: