You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Argument of type '() => { bar: { field: string; }; }' is not assignable to parameter of type '() => Record<"bar", Foo>'.
Type '{ bar: { field: string; }; }' is not assignable to type 'Record<"bar", Foo>'.
Types of property 'bar' are incompatible.
Type '{ field: string; }' is not assignable to type 'Foo'.
Types of property 'field' are incompatible.
Type 'string' is not assignable to type '"a" | "b" | "c"'.
One can coax the compiler into figuring things out via an explicit type parameter
foo<'bar'>(()=>({bar: {field: 'a'},}))
but it's not clear why this should be necessary. When foo is not generic, there's no problem:
This is a design limitation of our current approach to overload resolution. Context-sensitive functions (once whose parameters types, including this, may be affected by contextual type) will get their types the first time the function is visited. types in our current system do no evolve. so the first round of inference we still do not know what the return type of the function is, all we know is we have a generic type; that becomes the contextual type for the function return type. then we check the "a", and since that there is no contextual type that suggests a literal type, the string type is inferred.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.6.0-dev.201xxxxx
Code
Expected behavior:
This type checks.
Actual behavior:
One can coax the compiler into figuring things out via an explicit type parameter
but it's not clear why this should be necessary. When
foo
is not generic, there's no problem:The text was updated successfully, but these errors were encountered: