-
Notifications
You must be signed in to change notification settings - Fork 12.8k
type alternatives in arguments become function alternatives and are then inferred to a never argument. #61186
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
You might have wanted to use a non-distributive conditional type there: function voidOrNot<T = void>(): { f: [T] extends [void] ? () => void : (arg: T) => void } {
return null!;
} |
@Andarist that solved my issue, thanks! Thinking about this.... I left out that the oldest version of typescript (3.3.3) in the Playground changes ![]() (which was also wrong). If conditional types are meant to distribute, wouldn't transforming ![]() |
Searched more, looks like this is a duplicate of, or related to
|
That might be what you want to get in certain situations but the compiler can't predict your intention. A union distributes into another union |
I'm not convinced this is the best language decision, but thanks again for the tight workaround! |
π Search Terms
never alternative types ts2345
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.3#code/GYVwdgxgLglg9mABANzjAJgeQE4Dk5QA8AKogLwproB8AFAJQBciA3osM6QKYAeUXYdAGdKGRAH5EDctVHpEzWgENsAc070ZcxAF9WAKESJsXKCGxIwIADbWAhAG59O-fqgBPAA5dEAQQBC5IgARL7BiAA+If7BTvoQCEJQiADuMFAAFgDKMAC2ntZcxF4+FKgYOPhEocF09HFpmTn5hcXeAHTAtDX1rglgSanpGQBqVG2lcpUEhOU0DE6No+MlnQt9iclLvtb8FkqwyEUlQXPTRAF1DcM7e2AHMEcTa73bu1z7h8cdXT1xAPT-RAebxwYBDTK3D73L4TZhsDhSZRqZg9LRzTRRWjI9TRYKaMiyDG6fSA4ElMEQjJQz6Pb5cTqKFS4sBcI7YAlEqhOIA
π» Code
π Actual behavior
π Expected behavior
f(arg: AB) => void
is not expanded to(f(arg: A) => void) | (f(arg: B) => void)
... or that it's still callable if it is.Additional information about the issue
please feel free to suggest a better issue title, I'm having trouble picking a good name today!
The text was updated successfully, but these errors were encountered: