-
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
.d.ts files strip private property types, which can be used to distinguish instance types #38953
Comments
Removing the types is necessary for compatibility/implementation-hiding reasons. The correct fix would be for us to emit the variance measurement of |
A workaround is to use |
What if the compiler outputted |
This leads to confusing behavior where vscode (or your editor of choice) reports errors that the compiler doesn't catch when using project references. E.g. in this playground the editor can infer the type of However, if the type is imported via a .d.ts file (i.e. at compile time), the type of Given that it seems we can't annotate private members with their types, it would probably make sense to explicitly forbid using types of private members imported from .d.ts files. |
2 years later and ran exactly into this issue
Would like to clarifications inside docs on |
2 years later, exactly the same rabbithole and just stumbled across this 🤣 |
TypeScript Version: 4.0.0-dev.20200604
Search Terms:
private class property type declaration
Expected behavior: .d.ts files preserve the types of private properties, as these determine if an instance type is assignable to another
Actual behavior: .d.ts files strip private property type, creating an error
Related Issues: N/A
Code
Obviously, this is a contrived example, but this was an issue I ran into.
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: