-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional types
Milestone
Description
Bug Report
π Search Terms
ignored return type generic conditional
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
return
β― Playground Link
Playground link with relevant code
π» Code
type Foo<T> = {
template: T;
}
type Bar<T> = T extends boolean ? Foo<number> : Foo<string>;
type Baz<T extends boolean> = Bar<T> extends infer InferredFoo
? InferredFoo extends Foo<any>
? "yes"
: never
: never;
function test<T extends boolean>(opts: T) {
const x = false;
// If you comment the line below, this function starts
// returning Baz<T> as expected, which in turn makes `result`
// have the type "yes".
// The if statement below should have no impact to the
// return type of the function, other than adding `| null`.
// After all, you can force the return type of the function
// to be `Baz<T> | null` and it still works fine.
if (x) return null;
return {} as Baz<T>;
}
const result = test(true);π Actual behavior
result has type null
π Expected behavior
result should have type null | "yes"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional types