Closed
Description
TypeScript Version: 2.7.0-dev.20180112
Code
interface IX {
x: boolean;
}
function fn<T>(obj: T, props: Partial<T>): (T & IX) {
const xobj = obj as T & IX;
xobj.x = true;
for (const p in props) {
// The following line causes a compilation error:
// TS2322: Type 'Partial<T>[keyof T]' is not assignable to type '(T & IX)[keyof T]'.
xobj[p] = props[p];
}
return xobj;
}
Expected behavior:
This should compile since the members of Partial<T>
is a subset of the members of (T & IX)
.
This does compile in 2.7.0-dev.20180108.
Actual behavior:
The following error is emitted when compiled:
index.ts(9,9): error TS2322: Type 'Partial<T>[keyof T]' is not assignable to type '(T & IX)[keyof T]'.
Type 'T[keyof T]' is not assignable to type '(T & IX)[keyof T]'.
Type 'T' is not assignable to type 'T & IX'.
Type 'T' is not assignable to type 'IX'.
Related: