Closed
Description
TypeScript Version: 3.1.1-insiders.20180925
Search Terms:
is not assignable to, partial
Code
interface IItem {
id: string;
isOpen: boolean;
}
interface IRecord {
id: string;
}
type Upsertable<T> = Partial<T> & { id: string; };
class A<T extends IItem = IItem> {
protected setItem(partialItem: Upsertable<T>): void {
}
}
interface IMyItem extends IItem {
title: string;
}
class B<T extends IMyItem> extends A<T> {
constructor() {
super();
const id: string = 'uniqueId';
const isOpen: boolean = false;
this.setItem({ id, isOpen }); // error here:
// Argument of type '{ id: string; isOpen: boolean; }' is not assignable to parameter of type 'Upsertable<T>'.
// Type '{ id: string; isOpen: boolean; }' is not assignable to type 'Partial<T>'.
}
}
Expected behavior:
The given properties are valid with the type IMyItem, which in turn extends from IItem, and as all properties bar id are optional, having only isOpen
and id
should be fine.
Actual behavior:
Errors with Argument of type '{ id: string; isOpen: boolean; }' is not assignable to parameter of type 'Upsertable<T>'. Type '{ id: string; isOpen: boolean; }' is not assignable to type 'Partial<T>'.
Related Issues:
Maybe this bug: #12731?