Closed
Description
TypeScript Version: 3.5.3 - 3.7.0-dev.20191009
Search Terms: return type enforcement generic callable signature
Code
interface Foo {
value: number
}
type SomeCallType<T> = () => T;
const example: SomeCallType<Foo> = () => ({ value: 1, bar: 2 })
Expected behavior:
The above sample should not compile and instead emit ts(2322)
because bar
is not a valid property for Foo
Actual behavior:
The code will in fact compile and emit as if nothing were the matter.
Playground Link: here
Related Issues:
These may be related, given that they involve other cases where return types don't appear to be correctly enforced on callable signatures:
- Generic return type inferred only with explicitly typed (not inferred) parameter #31892 is probably the closest, having come across a limitation of return type inference, but in this case there is no inference, the generic type is explicitly provided and fails to correctly constrain the return type.
- ReturnType<F> in parameter of generic function breaks inference when
F
has one implicitly typed param #33042 deals with parameter inferences leading to incorrect return type inferences, but that doesn't apply here - Referencing ReturnType<FooT> in generic param, and passing a function that has one param causes incorrect type inference... #29133 is a longer version of that, but also has to do with linked inferences
- Correlated type constraint breaks under return type inference #32804 is that, yet again
- Can't assign result of function of type T to ReturnType<T> #31811 is return type inference being too strict, which is the opposite of this problem