mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Fix type of computed name following spread (#39319)
This commit is contained in:
parent
8b6a88700e
commit
ff1f449b99
@ -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 {
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
//// [spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts]
|
||||
declare const m: { [k: string]: string };
|
||||
const x: { [k: string]: string } = { ...m, ["a" + "b"]: "" };
|
||||
|
||||
//// [spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js]
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var _a;
|
||||
var x = __assign(__assign({}, m), (_a = {}, _a["a" + "b"] = "", _a));
|
||||
@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts ===
|
||||
declare const m: { [k: string]: string };
|
||||
>m : Symbol(m, Decl(spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts, 0, 13))
|
||||
>k : Symbol(k, Decl(spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts, 0, 20))
|
||||
|
||||
const x: { [k: string]: string } = { ...m, ["a" + "b"]: "" };
|
||||
>x : Symbol(x, Decl(spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts, 1, 5))
|
||||
>k : Symbol(k, Decl(spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts, 1, 12))
|
||||
>m : Symbol(m, Decl(spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts, 0, 13))
|
||||
>["a" + "b"] : Symbol(["a" + "b"], Decl(spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts, 1, 42))
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.ts ===
|
||||
declare const m: { [k: string]: string };
|
||||
>m : { [k: string]: string; }
|
||||
>k : string
|
||||
|
||||
const x: { [k: string]: string } = { ...m, ["a" + "b"]: "" };
|
||||
>x : { [k: string]: string; }
|
||||
>k : string
|
||||
>{ ...m, ["a" + "b"]: "" } : { [x: string]: string; }
|
||||
>m : { [k: string]: string; }
|
||||
>["a" + "b"] : string
|
||||
>"a" + "b" : string
|
||||
>"a" : "a"
|
||||
>"b" : "b"
|
||||
>"" : ""
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
// @strict: true
|
||||
declare const m: { [k: string]: string };
|
||||
const x: { [k: string]: string } = { ...m, ["a" + "b"]: "" };
|
||||
Loading…
x
Reference in New Issue
Block a user