-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Exclude<string, "foo"> is not working #38254
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
Comments
Not the most elegant, but here is a work-around. Edit. Another solution: |
This is limitation of What you are lookin is Negated types: #29317 and comment about your use case #29317 (comment) |
Thank you for comments! |
Yeah, unfortunately we're not wired up to "cut holes" out of infinitely large domains of types, and it appears that adding that assumption to the type system would make it incredibly painful to use. Regarding you might be able to get away with using |
since Function belongs to object, so a Function which return type is not object is still assignable to 'object | () => return type'. we need exclude Function from object. releated: microsoft/TypeScript#38254 https://stackoverflow.com/questions/24613955/is-there-a-type-in-typescript-for-anything-except-functions
TypeScript Version: 3.8.3 or earlier
Search Terms:
Exclude
,Conditional Types
Code
Expected behavior:
"bar"
is not assignable tobaz
.Actual behavior:
"bar"
is assignable tobaz
without any errors.Playground Link: https://www.typescriptlang.org/play/#code/FAFwngDgpgBAYgewTAvDAogDwMYBsCuAJlADwDOIATgJYB2A5gDQwBEARgIaUsB8A3MGDYEtCjE4AvAFzwkqVp24ChIsglxQAdLgT0AFJICUAoA
The text was updated successfully, but these errors were encountered: