Improve apparent type of mapped types with mapped type modifiers#58091
Improve apparent type of mapped types with mapped type modifiers#58091Andarist wants to merge 1 commit intomicrosoft:mainfrom
Conversation
| if (constraint.flags & TypeFlags.Index) { | ||
| const baseConstraint = getBaseConstraintOfType((constraint as IndexType).type); | ||
| if (baseConstraint && everyType(baseConstraint, t => isArrayOrTupleType(t) || isArrayOrTupleOrIntersection(t))) { | ||
| return instantiateType(target, prependTypeMapping(typeVariable, baseConstraint, type.mapper)); |
There was a problem hiding this comment.
The type.mapper here looks something like:
m1: T_id -> Box<string>[]
m2: m1: K -> K
m2: m1: T_id -> UnboxArray<T_outer>
m2: T_id -> UnboxArray<T_outer>Since typeVariable is T_id TS ended up "skipping" over the inner mapping of UnboxArray. The constraint (of the type) is keyof T_outer with a baseConstraint of Box<string>[].
In a sense, I'd like to map T_outer to baseConstraint (Box<string>[]), process that through type.mapper and then map T_id to that result (or smth along those lines). I couldn't find a clear way to do that given that we need to account for non-homomorphic instantiations of homomorphic mapped types here. Using the modifiers type does seem to do the trick but I'm not overly confident in this solution and I won't mind being proven that this is wrong 😉
|
@typescript-bot test it |
|
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
|
@jakebailey Here are the results of running the user tests comparing Everything looks good! |
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jakebailey Here are the results of running the top 400 repos comparing Everything looks good! |
|
Damn, I was close! :P It was worth a shot :) |
fixes #58060