Recursively mark object literals as non-fresh when checking assignability to intersections#8605
Conversation
`getRegularTypeOfObjectLiteral` marks an object literal as non-fresh so that excess object-property errors will not be reported. It is needed so that errors aren't reported when checking assignability to intersections or unions, for example. Previously, the function was not recursive, so nested object literals still erroneously gave the error. Now it's recursive.
| nested: { | ||
| d: 'yes', | ||
| e: 'no' | ||
| } |
There was a problem hiding this comment.
Another layer of nesting would be good to test as well.
|
@DanielRosenwasser can you take a look at the refactored code? (I looked at #8694 which you linked. It seems like the opposite of #7649 -- the compiler over-checks here, it under-checks there.) |
|
ping @DanielRosenwasser |
| return symbol; | ||
| } | ||
|
|
||
| function updateTypeOfMembers(type: Type, update: (propertyType: Type) => Type) { |
There was a problem hiding this comment.
transform or map might be a better word that doesn't imply mutation.
There was a problem hiding this comment.
Also note in a comment that this doesn't work for signatures of any kind.
|
OK, I addressed the comments, but didn't try to avoid creating a fresh SymbolTable. I think you are right that it's too complex to be worth it. |
| return members; | ||
| } | ||
|
|
||
| /** Mark an object literal as exempt from the excess properties check. |
There was a problem hiding this comment.
This doesn't actually mark an object as exempt, it creates a new non-fresh object that will be exempt if the old one wasn't.
|
Fix comment, then 👍 |
Fixes #7649