-
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
Private properties should still emit type #20979
Comments
That's pretty gnarly, and admittedly not something I'm sure we discussed back in #1532 and earlier. |
The temporary fix I use is to just have But this problem had plagued me, on and off, for a pretty long time, before I finally discovered the cause. I never thought to look at the type declaration file before! I would have this assignable-when-it-should-not-be problem for some projects and not on others, and couldn't see a pattern to reproducibility. So, I never brought it up. |
We can't really change the emit behavior as it stands because Without an extant property, we can't properly measure the variance behavior of the generic parameter, so just assuming that If This bug is about as old as TypeScript itself and this is the first we've heard of it, so asking the rare cases to add the workaround property (which can be |
|
TypeScript Version: 2.7.0-dev.20171229
Code
Expected behavior:
Actual behavior:
The problem comes when trying to use such a class from another package.
The assignment is okay because
x
isany
in the generated declaration, making bothGen<number>
andGen<string>
assignable to each other, when they shouldn't.A more concrete example is something like this,
It works fine in the package that declares it. But packages that use it will see
private _dummyCanBuild : any
, makingBuilder<true>
andBuilder<false>
assignable to each other. This would allow the user of the package to callbuild()
without having calledsetImportantValue()
.The text was updated successfully, but these errors were encountered: