-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
3.5.1 breaks simple unambiguous type guards? #31853
Comments
I am not sure why this doesn't work (and to my newbie understanding it should)... But I have found these workarounds |
@ziriax Btw. for me it won't compile even with TS version 3.4.5 |
Indeed, we were still using TS 3.4.0, it fails with 3.4.5, nice catch! function kaput4<K extends PrimitiveKind>(kind: PrimitiveKind) {
switch (kind) {
case PrimitiveKind.Float:
test(kind);
break;
}
} Thanks for the working code, it is amazing that a PS: Of course your function |
The sample code above has the same errors in every version of TypeScript going back 2.5, so whatever problem you have updating to 3.5.1, this isn't it. |
Ouch, then we oversimplified the code that broke, mea culpa, I will revise. |
The new errors you're seeing are likely related to #30769 and may be intended. |
@ahejlsberg You are 100% correct, the full signature of the code that breaks in our code is
From issue #30769 I can understand why this breaks now, but it is going to break a lot of our code base ;-) |
@ahejlsberg @ziriax Sorry, I am not able to see how it is related. And I am curious about why TS is able to infer the enum type when using |
The example declares a type parameter but never uses it. |
No, it uses it in the |
@Siegrift Your playground example declares |
We get some unexpected regression compiler errors in our code base when upgrading to
tsc 3.5.1
.We simplified the code for this bug report.
If this isn't a bug, it would be nice to know why this is now expected behavior, and what would be the recommended workaround?
TypeScript Version: 3.5.1
Search Terms:
3.5
,3.5.1
,type guard
Code
Expected behavior:
The compiles without errors (worked in 3.4.0)
Actual behavior:
Compiler error
Type 'PrimitiveKind' is not assignable to type 'PrimitiveKind.Float'.
for functionskaput1
,kaput2
andkaput3
.(As Siegrift found out below, it seems this behavior started from version 3.4.5)
Playground Link:
Demo
Related Issues:
#31833 #31837
The text was updated successfully, but these errors were encountered: