-
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
Can't use boolean as parameter for a function with overrides for parameter of type true and false #44967
Comments
Here's a more realistic example where this feature could actually made my code more correct and easy to read. I have something akin to following: function f1(input: 'a' | 'b'): 'c' | 'd' {
throw new Error('not implemented')
}
function f2(input: 'c' | 'd'): 'e' | 'f' {
throw new Error('not implemented')
}
function f3(input: 'e' | 'f'): 'g' | 'h' {
throw new Error('not implemented')
}
function f0(): 'a' | 'b' {
throw new Error('not implemented')
}
const ab = f0()
const cd = f1(ab)
const ef = f2(cd)
const gh = f3(ef) (In the real code those types aren't constants but tagged unions). This code is correct, but here the types of However, I know that in my real code, function f1(input: 'a'): 'c'
function f1(input: 'b'): 'd'
function f1(input: 'a' | 'b'): 'c' | 'd' {
throw new Error('not implemented')
}
function f2(input: 'c'): 'e'
function f2(input: 'd'): 'f'
function f2(input: 'c' | 'd'): 'e' | 'f' {
throw new Error('not implemented')
}
function f3(input: 'e'): 'g'
function f3(input: 'f'): 'h'
function f3(input: 'e' | 'f'): 'g' | 'h' {
throw new Error('not implemented')
}
function f0(): 'a' | 'b' {
throw new Error('not implemented')
}
const ab = f0()
const cd = f1(ab)
const ef = f2(cd)
const gh = f3(ef) ...but now, instead of better type inference, I get the error. |
See #14107 The call signature of
To produce your expected behavior, you should add a call signature.
|
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
🔎 Search Terms
Function overloading, sum types, function parameters, type inferrence
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
🙂 Expected behavior
Code compiles,
test(a)
result is inferred to be"true"|"false"
.The text was updated successfully, but these errors were encountered: