mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Fix stack overflow in JSX discriminated union logic (#46354)
* Use getContextFreeTypeOfExpression to avoid circularities * Add regression test
This commit is contained in:
@@ -22691,7 +22691,7 @@ namespace ts {
|
||||
const keyPropertyName = getKeyPropertyName(unionType);
|
||||
const propNode = keyPropertyName && find(node.properties, p => p.symbol && p.kind === SyntaxKind.PropertyAssignment &&
|
||||
p.symbol.escapedName === keyPropertyName && isPossiblyDiscriminantValue(p.initializer));
|
||||
const propType = propNode && getTypeOfExpression((propNode as PropertyAssignment).initializer);
|
||||
const propType = propNode && getContextFreeTypeOfExpression((propNode as PropertyAssignment).initializer);
|
||||
return propType && getConstituentTypeForKeyType(unionType, propType);
|
||||
}
|
||||
|
||||
@@ -26198,7 +26198,7 @@ namespace ts {
|
||||
concatenate(
|
||||
map(
|
||||
filter(node.properties, p => !!p.symbol && p.kind === SyntaxKind.JsxAttribute && isDiscriminantProperty(contextualType, p.symbol.escapedName) && (!p.initializer || isPossiblyDiscriminantValue(p.initializer))),
|
||||
prop => ([!(prop as JsxAttribute).initializer ? (() => trueType) : (() => checkExpression((prop as JsxAttribute).initializer!)), prop.symbol.escapedName] as [() => Type, __String])
|
||||
prop => ([!(prop as JsxAttribute).initializer ? (() => trueType) : (() => getContextFreeTypeOfExpression((prop as JsxAttribute).initializer!)), prop.symbol.escapedName] as [() => Type, __String])
|
||||
),
|
||||
map(
|
||||
filter(getPropertiesOfType(contextualType), s => !!(s.flags & SymbolFlags.Optional) && !!node?.symbol?.members && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName)),
|
||||
|
||||
Reference in New Issue
Block a user