-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Bad type checking for GenericType<boolean> vs GenericType<false> #33833
Comments
Could well be caused by #29478, and this may be a duplicate of #30390. It seems that the argument type in the signature of Not really sure how best to fix this. I wonder if variance markers can be used to control widening: a boolean type that instantiates an invariant type parameter should not produce a non-widening contextual type. |
I think both cases should fail. Because |
@xiaoxiangmoe Ideally the type would be inferred as |
This is a duplicate of #30390. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.7.0-dev.20191006
Search Terms: covariance, subtype, inference, value type (... honestly I have no idea what the right term for "
false
when used as a type" is, it's... probably not this though).Code:
Expected behavior: The code above should typecheck. Or, at the very least, both cases should fail, instead of assigning to an intermediate variable fixing the issue.
Actual behavior: I get an error like the following on the first call to
takesBoolGrid
:Playground Link: https://www.typescriptlang.org/play/?ts=3.7-Beta&ssl=1&ssc=1&pln=14&pc=1#code/MYGwhgzhAEDiBOBLAJgHgCoD5oG8CwAUNMdMAPYB2EALvAK7DVnwAUA7itQBYBc0FdALYAjAKbwANNC6jEAcy7U+AkeKnJRAMzB0Q1AGKIQIPugCUuaAF9CJaAHp70CGUGjomuhUaJK0NlyIwFzQstzi0GJcYABuojCQ0GAeRiDQzEkU0IgUALQADuDA7qIAjnSIMWAgohTU6ZrQgmD5UpoZogAeYIKForYkmqkA6ojcLFUgdKIA8vAAwtUgwmDAANam0AA+0CwswHTw8LVK0OhSncpCYpLQAJ5Xqrcol-zX4hYAvNjmFjg2BABhE83moviy1DAa3iACEyGQQAgUCw5EhkHwkWhhPCamAKJg-tZCI4zoEYMAdBB4kloNQ7vkSkdmIRIdCIHCEZiWBRRGw4GiWABGABsUhFbWqVLMZgA3IRiU4YXR6txEDBkGR4hQAOTUQg1epyaCffi8-nI8XQS3aEBSuUEVmwnFcuSywhAA
Related Issues: I looked, but sadly my search terms quickly brought me to a bunch of issues that assume more familiarity with tsc (and type system jargon, probably) than I have. (This is probably because the only terminology I have for describing this problem is, well, type system jargon that I only barely can say I understand).
Some notes that don't fit above which might help, possibly: this code used to work in like, typescript 2.something (I could probably find out which version it was on Monday if it would help).
I updated the code to the new typescript, and got this error, and assumed it was just typescript getting updated with some stricter behavior around variance. I complained online, and was asked to produce an example, and it turned out that the issue was weirder than I had though, as:
Point 2 seems weird, so I decided to file a bug.
Note that (IMO fairly unsurprisingly) the expression
takesBoolGrid(new Grid<boolean>(16, 16, false))
type checks fine, e.g. if the type is listed explicitly, no intermediate variable is needed. So I guess it's some kind of type inference thing too? Who knows... (hopefully someone here!)The text was updated successfully, but these errors were encountered: