-
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
Intersect interfaces instead of union #33070
Comments
But that would produce invalid results. If For example if you manually force an intersection:
The compiler will assume it calls |
Is this issue saying that Or is this issue saying that function Func1(options: Func1Options) {
options.name.toUpperCase();
}
function Func2(options: Func2Options) {
options.age.toFixed();
}
const selectedFunc = Math.random() < 0.99 ? Func1 : Func2;
selectedFunc({ age: 20 }); // 99% guarantee of kaboom At runtime, |
@MartinJohns’s comment shows why the current behaviour is the correct one. More details can be found here: #29011 |
Thank you, for description. Now I understand kind of philosophy of ts, |
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms: Intersection interfaces, Ternary operator, Intersect interfaces instead of union
Code
Expected behavior:
selectedFunc
acceptsFunc1Options
Actual behavior:
selectedFunc
acceptsFunc1Options & Func2Options
Playground Link: Playground
The text was updated successfully, but these errors were encountered: