Skip to content

Commit abebf15

Browse files
committed
Ensure '{ [key]: x } = obj' for generic key is the same as 'x = obj[key]'
1 parent 9daf69d commit abebf15

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,12 +4667,8 @@ namespace ts {
46674667
else {
46684668
// Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form)
46694669
const name = declaration.propertyName || <Identifier>declaration.name;
4670-
const exprType = isComputedPropertyName(name)
4671-
? checkComputedPropertyName(name)
4672-
: isIdentifier(name)
4673-
? getLiteralType(unescapeLeadingUnderscores(name.escapedText))
4674-
: checkExpression(name);
4675-
const declaredType = checkIndexedAccessIndexType(getIndexedAccessType(getApparentType(parentType), exprType, name), name);
4670+
const exprType = getLiteralTypeFromPropertyName(name);
4671+
const declaredType = checkIndexedAccessIndexType(getIndexedAccessType(parentType, exprType, name), name);
46764672
type = getFlowTypeOfReference(declaration, getConstraintForLocation(declaredType, declaration.name));
46774673
}
46784674
}
@@ -9528,7 +9524,7 @@ namespace ts {
95289524
// object type. Note that for a generic T and a non-generic K, we eagerly resolve T[K] if it originates in
95299525
// an expression. This is to preserve backwards compatibility. For example, an element access 'this["foo"]'
95309526
// has always been resolved eagerly using the constraint type of 'this' at the given location.
9531-
if (isGenericIndexType(indexType) || !(accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression) && isGenericObjectType(objectType)) {
9527+
if (isGenericIndexType(indexType) || !(accessNode && accessNode.kind !== SyntaxKind.IndexedAccessType) && isGenericObjectType(objectType)) {
95329528
if (objectType.flags & TypeFlags.AnyOrUnknown) {
95339529
return objectType;
95349530
}

0 commit comments

Comments
 (0)