Improve optionality detection in mapped type indexed access substitutions - #57946
Conversation
|
|
||
| function getModifiersTypeOptionality(type: Type): number { | ||
| return type.flags & TypeFlags.Intersection ? Math.max(...map((type as IntersectionType).types, getModifiersTypeOptionality)) : | ||
| return type.flags & TypeFlags.Intersection ? Math.min(...map((type as IntersectionType).types, getModifiersTypeOptionality)) : |
There was a problem hiding this comment.
Only claim that intersections add optionality when all constituents do so. Previously, optionality in any constituent would cause us to claim optionality for the entire intersection, but that is too aggressive.
| return addOptionality(instantiatedTemplateType, /*isProperty*/ true, getCombinedMappedTypeOptionality(objectType) > 0); | ||
| const isOptional = getMappedTypeOptionality(objectType) > 0 || (isGenericType(objectType) ? | ||
| getModifiersTypeOptionality(getModifiersTypeFromMappedType(objectType)) > 0 : | ||
| couldAccessOptionalProperty(objectType, index)); |
There was a problem hiding this comment.
When processing a substitution for { [P in K]: E}[X], when { [P in K]: E } is non-generic, examine the actual properties selected by X to see if some are optional.
|
TypeScript Bot (@typescript-bot) test top200 |
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user tests comparing Everything looks good! |
|
Hey Anders Hejlsberg (@ahejlsberg), the results of running the DT tests are ready. There were interesting changes: Branch only errors:Package: vue3-carousel-3d |
|
Anders Hejlsberg (@ahejlsberg) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top 400 repos comparing Something interesting changed - please have a look. Details
|
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Anders Hejlsberg (@ahejlsberg), the results of running the DT tests are ready. Everything looks the same! |
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user tests comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
|
Anders Hejlsberg (@ahejlsberg) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top 400 repos comparing Everything looks good! |
|
Tests and performance are clean. This is ready for a review. |
|
be careful merging, this will almost guaranteed break main like the last two PRs. |
Fixes #57860.