Use const context in intersections containing const type variables (#55779)

This commit is contained in:
Mateusz Burzyński
2023-09-19 23:26:14 +02:00
committed by GitHub
parent 79736eff89
commit 6e01b06616
4 changed files with 132 additions and 1 deletions

View File

@@ -13912,7 +13912,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function isConstTypeVariable(type: Type | undefined, depth = 0): boolean {
return depth < 5 && !!(type && (
type.flags & TypeFlags.TypeParameter && some((type as TypeParameter).symbol?.declarations, d => hasSyntacticModifier(d, ModifierFlags.Const)) ||
type.flags & TypeFlags.Union && some((type as UnionType).types, t => isConstTypeVariable(t, depth)) ||
type.flags & TypeFlags.UnionOrIntersection && some((type as UnionOrIntersectionType).types, t => isConstTypeVariable(t, depth)) ||
type.flags & TypeFlags.IndexedAccess && isConstTypeVariable((type as IndexedAccessType).objectType, depth + 1) ||
type.flags & TypeFlags.Conditional && isConstTypeVariable(getConstraintOfConditionalType(type as ConditionalType), depth + 1) ||
type.flags & TypeFlags.Substitution && isConstTypeVariable((type as SubstitutionType).baseType, depth) ||