-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object Properties Spread with Generic Object Types not allowed #15792
Comments
@mhegazy but it works in 2.2.1 - it is blocker to updated to 2.3 for us :-( |
Not sure what you mean by that, this has always been an error.. c:\test>type b.ts
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> {
setProperties(props: P) {
const newProps = { ...props };
}
}
c:\test>node c:\releases\2.2.1\tsc.js --version
Version 2.2.1
c:\test>node c:\releases\2.2.1\tsc.js b.ts
b.ts(3,24): error TS2698: Spread types may only be created from object types.
b.ts(9,24): error TS2698: Spread types may only be created from object types.
b.ts(15,24): error TS2698: Spread types may only be created from object types.
b.ts(21,24): error TS2698: Spread types may only be created from object types.
c:\test>node c:\releases\2.2.2\tsc.js --version
Version 2.2.2
c:\test>node c:\releases\2.2.2\tsc.js b.ts
b.ts(3,24): error TS2698: Spread types may only be created from object types.
b.ts(9,24): error TS2698: Spread types may only be created from object types.
b.ts(15,24): error TS2698: Spread types may only be created from object types.
b.ts(21,24): error TS2698: Spread types may only be created from object types.
c:\test>node c:\releases\2.3.2\tsc.js --version
Version 2.3.2
c:\test>node c:\releases\2.3.2\tsc.js b.ts
b.ts(3,24): error TS2698: Spread types may only be created from object types.
b.ts(9,24): error TS2698: Spread types may only be created from object types.
b.ts(15,24): error TS2698: Spread types may only be created from object types.
b.ts(21,24): error TS2698: Spread types may only be created from object types. do you mean spread in JSX? |
Oh, sorry - yes, we have this error in JSX. I just have decided that is the same errors - the symptoms is very similar :) |
@mhegazy For |
TypeScript Version: 2.3.2
Code
Playground Example
Expected behavior:
That properties are spread on class
Bar
, classBaz
, and classQat
.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.The text was updated successfully, but these errors were encountered: