-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Remove empty object types from intersection types #15033
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
@@ -59,5 +59,5 @@ exports.runSampleBreaks = runSampleBreaks; | |||
export declare class bluebird<T> { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as the next line? I'm a bit confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ends are different look closer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.