Closed
Description
TypeScript Version: 3.3.0-dev.20190125
Search Terms:
covariance
Code
type Injector<TContext> = {
resolve: <T extends keyof TContext>() => T extends keyof TContext ? TContext[T] : never;
}
const foo: Injector<{ foo: string, bar: string }> = {} as any;
const bar: Injector<{ bar: string }> = foo; // no error
console.log(bar);
Expected behavior:
No compiler error with --strictFunctionTypes
. As was the case in TS 3.2.2
Actual behavior:
Compiler error (since TS 3.2.4)
index.ts:18:7 - error TS2322: Type 'Injector<{ foo: string; bar: string; }>' is not assignable to type 'Injector<{ bar: string; }>'.
Property 'foo' is missing in type '{ bar: string; }' but required in type '{ foo: string; bar: string; }'.
18 const bar: Injector<{ bar: string }> = foo;
~~~
index.ts:17:23
17 const foo: Injector<{ foo: string, bar: string }> = {} as any;
~~~
'foo' is declared here.
Related Issues:
(maybe): #28752