Fix #13556: enable rest/spread on object#13558
Conversation
| let a = 12; | ||
| let shortCutted: { a: number, b: string } = { ...o, a } | ||
| // non primitive | ||
| let spreadNonPrimitve = { ...<object>{}} |
There was a problem hiding this comment.
typo: Primitive
(and missing some semi-colons, not very important in tests though)
|
|
||
| // non primitive | ||
| let spreadNonPrimitve = { ...<object>{}} | ||
| >spreadNonPrimitve : { constructor: Function; toString(): string; toLocaleString(): string; valueOf(): Object; hasOwnProperty(v: string): boolean; isPrototypeOf(v: Object): boolean; propertyIsEnumerable(v: string): boolean; } |
There was a problem hiding this comment.
spreadNonPrimitive should be {}. It looks like getApparentType gets called somewhere, probably in getSpreadType's call to getPropertiesOfType(right). I think you need a special case in getSpreadType that returns emptyObjectType.
There was a problem hiding this comment.
Yes, getPropertiesOfType does call getApparentType. Currently spreading Object type also gets all properties on GlobalObjectType, is this desirable?
There was a problem hiding this comment.
No. Just like spreading number in javascript results in {} not { toString(), toFixed() ... }, spreading object should not get the properties of globalObjectType.
(Note that spreading number in typescript is illegal because it's useless, probably a mistake. Spreading object seems more useful.)
|
Also, I don't think the non-primitiveness should pass through. Spread types already destroy lots of information, and I think it's fine to convert |
|
Thanks! 😄 |
Fixes #13556, I wonder if
non-primitivenessshould pass to spread type?