Remove empty object types from intersection types#15033
Conversation
sandersn
left a comment
There was a problem hiding this comment.
Just one question.
As future work, it would be nice to combine all anonymous types together, eg D & { a: number } & { b: string } & { } should become D & { a: number, b: string }
| !t.numberIndexInfo; | ||
| } | ||
|
|
||
| function isEmptyObjectType(type: Type) { |
There was a problem hiding this comment.
why can't we use (type===emptyObjectType) here? Do we really have to resolve every type and then check its structure?
There was a problem hiding this comment.
We create a fresh object type whenever an object literal is declared with an alias (such that we can associate a name with it). Likewise we create a fresh object type for each object literal expression (although we could potentially special case an empty object literal). Since these are all distinct object identities, we need to compare structure.
|
thanks! |
| static all: Array<bluebird<any>>; | ||
| } | ||
| export declare function runSampleWorks<A, B, C, D, E>(a: bluebird<A>, b?: bluebird<B>, c?: bluebird<C>, d?: bluebird<D>, e?: bluebird<E>): Promise<(<T>(f: (a: A, b?: B, c?: C, d?: D, e?: E) => T) => T) & {}>; | ||
| export declare function runSampleWorks<A, B, C, D, E>(a: bluebird<A>, b?: bluebird<B>, c?: bluebird<C>, d?: bluebird<D>, e?: bluebird<E>): Promise<(<T>(f: (a: A, b?: B, c?: C, d?: D, e?: E) => T) => T)>; |
There was a problem hiding this comment.
Isn't this the same as the next line? I'm a bit confused.
There was a problem hiding this comment.
the ends are different look closer
There was a problem hiding this comment.
Right, I was checking the js transpilation. (facepalm)
With this PR we remove empty object type literals from intersection types that already contain other object types. For example, the intersection
{ x: number } & {}is reduced to just{ x: number }.Fixes #14762.