Use typeof enum to resolve members.
Use getTypeOfSymbol >> resolveStructuredTypeMembers >> properties instead of looking at declarations.
This commit is contained in:
parent
7530409695
commit
da8e19e191
2 changed files with 6 additions and 35 deletions
|
@ -5762,13 +5762,13 @@ namespace ts {
|
|||
target.symbol.flags & SymbolFlags.ConstEnum) {
|
||||
return Ternary.False;
|
||||
}
|
||||
const targetMembers = getEnumMembers(target.symbol);
|
||||
const targetNames = arrayToMap(targetMembers, member => getTextOfPropertyName(<PropertyName>member.name));
|
||||
for (const member of getEnumMembers(source.symbol)) {
|
||||
const name = getTextOfPropertyName(<PropertyName>member.name);
|
||||
if (!hasProperty(targetNames, name)) {
|
||||
const sourceMembers = resolveStructuredTypeMembers(getTypeOfSymbol(source.symbol)).properties;
|
||||
const targetMembers = resolveStructuredTypeMembers(getTypeOfSymbol(target.symbol)).properties;
|
||||
const targetNames = arrayToMap(targetMembers, member => member.name);
|
||||
for (const member of sourceMembers) {
|
||||
if (!hasProperty(targetNames, member.name)) {
|
||||
reportError(Diagnostics.Property_0_is_missing_in_type_1,
|
||||
name,
|
||||
member.name,
|
||||
typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType));
|
||||
return Ternary.False;
|
||||
}
|
||||
|
@ -5777,20 +5777,6 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function getEnumMembers(symbol: Symbol): EnumMember[] {
|
||||
const declarations = getDeclarationsOfKind(symbol, SyntaxKind.EnumDeclaration);
|
||||
if (!declarations) {
|
||||
return emptyArray;
|
||||
}
|
||||
const members: EnumMember[] = [];
|
||||
for (const declaration of declarations) {
|
||||
for (const member of (<EnumDeclaration>declaration).members) {
|
||||
members.push(member);
|
||||
}
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
// Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case
|
||||
// when structural type comparisons have been started for 10 or more instantiations of the same generic type. It is possible,
|
||||
// though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely expanding.
|
||||
|
|
|
@ -27,21 +27,6 @@ namespace ts {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
export function getDeclarationsOfKind(symbol: Symbol, kind: SyntaxKind): Declaration[] {
|
||||
const declarations = symbol.declarations;
|
||||
if (declarations) {
|
||||
const declarationsOfKind: Declaration[] = [];
|
||||
for (const declaration of declarations) {
|
||||
if (declaration.kind === kind) {
|
||||
declarationsOfKind.push(declaration);
|
||||
}
|
||||
}
|
||||
return declarationsOfKind;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export interface StringSymbolWriter extends SymbolWriter {
|
||||
string(): string;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue