Fix type of computed name following spread (#39319)

This commit is contained in:
Wesley Wigham
2020-06-30 13:37:59 -07:00
committed by GitHub
parent 8b6a88700e
commit ff1f449b99
5 changed files with 57 additions and 4 deletions

View File

@@ -23836,10 +23836,15 @@ namespace ts {
return links.resolvedType;
}
function isSymbolWithNumericName(symbol: Symbol) {
const firstDecl = symbol.declarations?.[0];
return isNumericLiteralName(symbol.escapedName) || (firstDecl && isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
}
function getObjectLiteralIndexInfo(node: ObjectLiteralExpression, offset: number, properties: Symbol[], kind: IndexKind): IndexInfo {
const propTypes: Type[] = [];
for (let i = offset; i < properties.length; i++) {
if (kind === IndexKind.String || isNumericName(node.properties[i].name!)) {
if (kind === IndexKind.String || isSymbolWithNumericName(properties[i])) {
propTypes.push(getTypeOfSymbol(properties[i]));
}
}
@@ -23892,8 +23897,7 @@ namespace ts {
}
let offset = 0;
for (let i = 0; i < node.properties.length; i++) {
const memberDecl = node.properties[i];
for (const memberDecl of node.properties) {
let member = getSymbolOfNode(memberDecl);
const computedNameType = memberDecl.name && memberDecl.name.kind === SyntaxKind.ComputedPropertyName && !isWellKnownSymbolSyntactically(memberDecl.name.expression) ?
checkComputedPropertyName(memberDecl.name) : undefined;
@@ -23980,7 +23984,7 @@ namespace ts {
checkSpreadPropOverrides(type, allPropertiesTable, memberDecl);
}
spread = getSpreadType(spread, type, node.symbol, objectFlags, inConstContext);
offset = i + 1;
offset = propertiesArray.length;
continue;
}
else {