-
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
Generics; ReturnType<Function> not assignable to ReturnType<Function & (conditional type)> #31602
Comments
Shorter repro, that shows it also fails for string assignments, function bar<F>(f: F) {
//Fail
//Type '() => any' is not assignable to type 'F extends any ? unknown : unknown'
const t: (
F extends any ? unknown : unknown
) = ((): any => 3);
//OK!
const t2: (
unknown
) = ((): any => 3);
//Fail
//Type 'string' is not assignable to type 'F extends any ? string : string'.
const e: (
F extends any ? string : string
) = ("test" as string);
//Fail
//Type 'string' is not assignable to type 'F extends any ? string : string'.
const e2: (
Extract<F extends any ? string : string, string>
) = ("test" as string);
//OK!
const e3: (
string
) = ("test" as string);
} |
For generics, I feel like if the true and false branches of a conditional type both extend some type I'm unsure how unfeasible it is, though. |
See #26933 |
Ah. I see there's a PR open for it already. I guess I can close this, and wait patiently for #30639 or some successor to get merged. |
TypeScript Version: TS Playground version (3.4.1), 3.5.0-dev.20190523
Search Terms: ReturnType, function, conditional type
Code
Expected behavior:
All failures should work.
Actual behavior:
They do not work.
Playground Link: Playground
Related Issues:
The text was updated successfully, but these errors were encountered: