Uh oh!
There was an error while loading. Please reload this page.
Consider index signatures as optional properties in contextual type discrimination - #54596
Conversation
| const filtered = contains(include, Ternary.False) ? getUnionType(types.filter((_, i) => include[i])) : target; | ||
| return filtered.flags & TypeFlags.Never ? target : filtered; | ||
| function getTypeOfPropertyOrOptionalIndexSignature(type: Type, name: __String): Type | undefined { |
There was a problem hiding this comment.
I feel like this function might already exist, but I couldn't find it.
There was a problem hiding this comment.
There's getTypeOfPropertyOrIndexSignature (used by narrowTypeByDiscriminant!). Consider replacing that function and making it take a parameter on whether to add optionality for index signatures.
TypeScript Bot (@typescript-bot) test this |
Heya Gabriela Araujo Britto (@gabritto), I've started to run the parallelized Definitely Typed test suite on this PR at c66c0d1. You can monitor the build here. Update: The results are in! |
Heya Gabriela Araujo Britto (@gabritto), I've started to run the diff-based user code test suite on this PR at c66c0d1. You can monitor the build here. Update: The results are in! |
Heya Gabriela Araujo Britto (@gabritto), I've started to run the extended test suite on this PR at c66c0d1. You can monitor the build here. |
Heya Gabriela Araujo Britto (@gabritto), I've started to run the perf test suite on this PR at c66c0d1. You can monitor the build here. Update: The results are in! |
Heya Gabriela Araujo Britto (@gabritto), I've started to run the diff-based top-repos suite on this PR at c66c0d1. You can monitor the build here. Update: The results are in! |
TypeScript Bot (typescript-bot)
commented
Jun 10, 2023
Gabriela Araujo Britto (@gabritto) Here are the results of running the user test suite comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Something interesting changed - please have a look. Details
|
TypeScript Bot (typescript-bot)
commented
Jun 10, 2023
Gabriela Araujo Britto (@gabritto) Here they are:CompilerComparison Report - main..54596
System
Hosts
Scenarios
TSServerComparison Report - main..54596
System
Hosts
Scenarios
StartupComparison Report - main..54596
System
Hosts
Scenarios
Developer Information: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TypeScript Bot (typescript-bot)
commented
Jun 10, 2023
Gabriela Araujo Britto (@gabritto) Here are the results of running the top-repos suite comparing Everything looks good! |
TypeScript Bot (typescript-bot)
commented
Jun 10, 2023
Hey Gabriela Araujo Britto (@gabritto), the results of running the DT tests are ready. |
Uh oh!
There was an error while loading. Please reload this page.
Rodrigo Leitão (ImRodry)
commented
Jul 3, 2023
This didn't land in 5.1.6 right? When is it expected to be released? |
Jake Bailey (jakebailey)
commented
Jul 5, 2023
This is in the 5.2 beta (also noted in the issue's milestone). |
Fixes#54498.
The fix is suggested and described by Nebojša Cvetković (@nebkat) in this comment: #54498 (comment).
When we try to discriminate a contextual type, we consider the omission of a property to be a factor to discriminate in
discriminateTypeByDiscriminableItems's implementation, but then during that process, when looking up a property in one of the candidate types, we would not consider matching index signatures and therefore we would discard the type with the index signature. Now, when looking up a property in one of the candidate types, we also consider matching on index signatures.