Conversation
weswigham
left a comment
There was a problem hiding this comment.
This will actually have a perf impact, too - rather than, say, a single {} & string intersection type existing, we'll have a {} & string for every empty object type made (that eventually gets intersected). That's how nonempty objects work, so not surprising - just a remark that it could affect performance in some way. Probably not much, since most {} in intersections I'd guess are the {} made in the compiler and used as the base constraint/inference failure type... But everwhere someone's written T={} (which is pretty often in a lot of the react stuff I've seen), we'll now be manufacturing new intersection identities.
| if (getObjectFlags(type) & ObjectFlags.Anonymous && isEmptyObjectType(type)) { | ||
| includes |= TypeFlags.EmptyObject; | ||
| if (isEmptyAnonymousObjectType(type)) { | ||
| if (!(includes & TypeFlags.EmptyObject)) { |
There was a problem hiding this comment.
There's never a situation where we'd need to preserve multiple different empty types... Right?
|
I don't expect this to affect performance in any measurable way. Regarding preservation of multiple empty object types, there are just two facts that matter for empty object types in intersections, one being whether the intersection contains any empty object types, and the other being whether any of those object types originate in an object literal type (for which we can automatically infer an index signature). We didn't track the second fact at all before. With this PR we do because we preserve the (first) actual empty object type as opposed to substituting our generic |
|
Theoretically there's also the JSLiteral and JSXAttributes object flags (which can both appear on empty object literal types from JS files and jsx attributes, respectively) that affect noImplicitAny and excess property errors, respectively. |
With this PR we properly preserve the origin of empty object literal types in intersections such that the logic that automatically infers index signatures for object literal types continues to work.
Fixes #20225.
Fixes #27044.