mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 21:32:45 -05:00
Merge pull request #49912 from microsoft/fix/47508
fix(47508): noUncheckedIndexedAccess with enums Type narrowed
This commit is contained in:
@@ -15814,7 +15814,18 @@ namespace ts {
|
||||
return accessFlags & AccessFlags.IncludeUndefined ? getUnionType([indexInfo.type, undefinedType]) : indexInfo.type;
|
||||
}
|
||||
errorIfWritingToReadonlyIndex(indexInfo);
|
||||
return accessFlags & AccessFlags.IncludeUndefined ? getUnionType([indexInfo.type, undefinedType]) : indexInfo.type;
|
||||
// When accessing an enum object with its own type,
|
||||
// e.g. E[E.A] for enum E { A }, undefined shouldn't
|
||||
// be included in the result type
|
||||
if ((accessFlags & AccessFlags.IncludeUndefined) &&
|
||||
!(objectType.symbol &&
|
||||
objectType.symbol.flags & (SymbolFlags.RegularEnum | SymbolFlags.ConstEnum) &&
|
||||
(indexType.symbol &&
|
||||
indexType.flags & TypeFlags.EnumLiteral &&
|
||||
getParentOfSymbol(indexType.symbol) === objectType.symbol))) {
|
||||
return getUnionType([indexInfo.type, undefinedType]);
|
||||
}
|
||||
return indexInfo.type;
|
||||
}
|
||||
if (indexType.flags & TypeFlags.Never) {
|
||||
return neverType;
|
||||
|
||||
Reference in New Issue
Block a user