Closed
Description
TypeScript Version: 2.5.3
(Tested at https://www.typescriptlang.org/play/)
Looks like Typescript is not correctly evaluating the generic return type where all the fields are optional.
Here is the minimal case.
Code
interface Base { id: string }
type Spec<T extends Base> = { [K in keyof T]?: T[K] }
export const makeSpec = <T extends Base>(id: string): Spec<T> => {
return { id }
}
Expected behavior:
Should compile
Actual behavior:
It throws an error for second last line:
Type '{ id: string; }' is not assignable to type 'Spec<T>'.
The compiler doesn't error on this:
interface A extends Base { name: string }
const spec: Spec<A> = { id: 'test' }
I feel it is a bug but I may be misunderstanding something.