-
Notifications
You must be signed in to change notification settings - Fork 12.8k
More precise property-overwritten-by-spread errors #37192
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
Trying to do this check in getSpreadType just doesn't have enough information, so I moved it to checkObjectLiteral, which is a better place for issuing errors anyway. Unfortunately, the approach is kind of expensive in that it 1. creates a new map for each property and 2. iterates over all properties of the spread type, even if it's a union. I have some ideas to improve (1) that might work out. I'm not sure how bad (2) is since we're going to iterate over all properties of all constituents of a union. Fixes #36779
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.
Small nit that should remove some casts, but overall I like this more than the awkward isParentTypeNullable
flag on getSpreadType
.
src/compiler/checker.ts
Outdated
@@ -22560,6 +22548,7 @@ namespace ts { | |||
let patternWithComputedProperties = false; | |||
let hasComputedStringProperty = false; | |||
let hasComputedNumberProperty = false; | |||
const propertyDeclarations = createMap<Symbol>(); |
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.
createSymbolTable
or createUnderscoreEscapedMap
tbh
@typescript-bot perf test this |
Heya @sandersn, I've started to run the perf test suite on this PR at 35bbfdc. You can monitor the build here. Update: The results are in! |
@sandersn Here they are:Comparison Report - master..37192
System
Hosts
Scenarios
|
Perf seems OK as-is, so I'm going to skip any fanciness and just change the name and constructor of (I was going to try to spill from propertiesTable to propertyDeclarations, not creating propertyDeclarations in object literals with no spreads. Fancy, but takes more code and harder to read.) |
Trying to do this check in getSpreadType just doesn't have enough information, so I moved it to checkObjectLiteral, which is a better place for issuing errors anyway.
Unfortunately, the approach is kind of expensive in that it
I have some ideas to improve (1) that might work out. I'm not sure how bad (2) is since we're going to iterate over all properties of all
constituents of a union.
Fixes #36779