-
Notifications
You must be signed in to change notification settings - Fork 12.8k
union types not type guarded #32928
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
Labels
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Comments
Cool makes sense, here's a smaller test case also: // Callable
type F = (...args: any[]) => any;
// Callable but intersected
type F2 = F & { inject?: string[] }
declare const a: string | F2
if (typeof a == 'function') {
// only F2
a
} else {
// Should be only a string
a
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
TypeScript Version: 3.5.2
**Search Terms:extended function type restriction
Code
Expected behavior: x in function f should be of type C at the point of the return statement
Actual behavior: x is considered as C or F2, apparently because of the combined type (it works well if we replace F2 with F)
Playground Link: https://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEDCBQBve1XQHZgLYFMBc0EALgE4CW6A5gNwprAD26xJArsEQyQBQAO5ANzBEc0ABZh0AExA4SBAGIBKOqmRoN0ImLIQAdJlzQAvOMky5B7DloaAvvAfwiAT16iFJ6Nz2+wJSggCSRcAbQBdJRMAPmgQ2mc3DwAmL08AMmhEaAoAKxwOAH4CFgpKCOgnADNWdA4yJmgq7gAPAlhoAB9oBWSlPAR1NDIq71d3BlGWk1MAchq6ogb0WZVNNGnTdBwAdzhuKqUEjRIcIlYSdGgW2jsgA
Related Issues: #27143
The text was updated successfully, but these errors were encountered: