mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Add index signature for anonymous object literal type (#37903)
* Use ts.map for stylistic consistency * Show error only if noImplicitAny is set * Accept baseline for noImplicitAnyIndexing * Fix lint error * Add test cases for indexedAccessWithFreshObjectLiteral
This commit is contained in:
@@ -13878,6 +13878,19 @@ namespace ts {
|
||||
return anyType;
|
||||
}
|
||||
if (accessExpression && !isConstEnumObjectType(objectType)) {
|
||||
if (isObjectLiteralType(objectType)) {
|
||||
if (noImplicitAny && indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) {
|
||||
diagnostics.add(createDiagnosticForNode(accessExpression, Diagnostics.Property_0_does_not_exist_on_type_1, (indexType as StringLiteralType).value, typeToString(objectType)));
|
||||
return undefinedType;
|
||||
}
|
||||
else if (indexType.flags & (TypeFlags.Number | TypeFlags.String)) {
|
||||
const types = map((<ResolvedType>objectType).properties, property => {
|
||||
return getTypeOfSymbol(property);
|
||||
});
|
||||
return getUnionType(append(types, undefinedType));
|
||||
}
|
||||
}
|
||||
|
||||
if (objectType.symbol === globalThisSymbol && propName !== undefined && globalThisSymbol.exports!.has(propName) && (globalThisSymbol.exports!.get(propName)!.flags & SymbolFlags.BlockScoped)) {
|
||||
error(accessExpression, Diagnostics.Property_0_does_not_exist_on_type_1, unescapeLeadingUnderscores(propName), typeToString(objectType));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user