-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
TypeScript Version: 3.7.2, nightly
Search Terms:
Generator can't infer that string belongs to a union in return type
Code
type FooType = { a: 'foo' };
type G = Generator<any, FooType, any>;
function* broken(): G {
return {
a: 'foo'
/*
Type 'string' is not assignable to type '"foo"'.(2322)
input.ts(1, 18): The expected type comes from property 'a' which is declared here on type 'FooType'
*/
}
}
function* workaround1(): G {
const rval: FooType = { a: 'foo' };
return rval;
}
function* workaround2(): G {
return {
a: 'foo' as const
}
}Expected behavior:
The return type shouldn't need these workarounds to know that 'foo' belongs to the union type.
Actual behavior:
Error described above. I included a couple workarounds that don't seem like they should be necessary, but are.
Related Issues: None as far as i could find
falsandtru and ExE-Boss
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone