Skip to content

Commit

Permalink
fix(60186): Quick fix "add missing properties" fails with enums from …
Browse files Browse the repository at this point in the history
…other module (#60191)
  • Loading branch information
a-tarasyuk authored Oct 14, 2024
1 parent 460be92 commit e99e6e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/services/codefixes/fixAddMissingMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ function tryGetValueFromType(context: CodeFixContextBase, checker: TypeChecker,
}
if (type.flags & TypeFlags.EnumLike) {
const enumMember = type.symbol.exports ? firstOrUndefinedIterator(type.symbol.exports.values()) : type.symbol;
const name = checker.symbolToExpression(type.symbol.parent ? type.symbol.parent : type.symbol, SymbolFlags.Value, /*enclosingDeclaration*/ undefined, /*flags*/ NodeBuilderFlags.UseFullyQualifiedType);
const symbol = type.symbol.parent && type.symbol.parent.flags & SymbolFlags.RegularEnum ? type.symbol.parent : type.symbol;
const name = checker.symbolToExpression(symbol, SymbolFlags.Value, /*enclosingDeclaration*/ undefined, /*flags*/ NodeBuilderFlags.UseFullyQualifiedType);
return enumMember === undefined || name === undefined ? factory.createNumericLiteral(0) : factory.createPropertyAccessExpression(name, checker.symbolToString(enumMember));
}
if (type.flags & TypeFlags.NumberLiteral) {
Expand Down
24 changes: 24 additions & 0 deletions tests/cases/fourslash/codeFixAddMissingProperties32.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path="fourslash.ts" />

// @filename: E.ts
////export enum E {
//// A,
//// B,
////}

// @filename: foo.ts
////import { E } from "./E"
////type T = {
//// e: E,
////}
////[|const t: T = { }|]

goTo.file('foo.ts');
verify.codeFix({
index: 0,
description: ts.Diagnostics.Add_missing_properties.message,
newRangeContent:
`const t: T = {
e: E.A
}`,
});

0 comments on commit e99e6e2

Please sign in to comment.