Closed
Description
TypeScript Version: 2.3.2
Code
class Foo<P> {
setProperties(props: P) {
const newProps = { ...props };
}
}
class Bar<P extends object> {
setProperties(props: P) {
const newProps = { ...props };
}
}
class Baz<P extends { [prop: string]: any; }> {
setProperties(props: P) {
const newProps = { ...props };
}
}
class Qat<P extends object = object> {
setProperties(props: P) {
const newProps = { ...props };
}
}
Expected behavior:
That properties are spread on class Bar
, class Baz
, and class Qat
.
Actual behavior:
All three cases report that Spread types may only be created from object types.
In all cases, the generic could be inferred to be of an object type, so the restriction seems to be arbitrary.