diff --git a/src/services/completions.ts b/src/services/completions.ts index 9b2747db14d2f..9ac50ed817c6f 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -3529,6 +3529,7 @@ namespace ts.Completions { // function f(x: T) {} // f({ abc/**/: "" }) // `abc` is a member of `T` but only because it declares itself function hasDeclarationOtherThanSelf(member: Symbol) { + if (!length(member.declarations)) return true; return some(member.declarations, decl => decl.parent !== obj); } } diff --git a/tests/cases/fourslash/completionListInObjectLiteral6.ts b/tests/cases/fourslash/completionListInObjectLiteral6.ts new file mode 100644 index 0000000000000..296b3c011251b --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectLiteral6.ts @@ -0,0 +1,22 @@ +/// + +////const foo = { +//// a: "a", +//// b: "b" +////}; +////function fn(obj: T, events: { [Key in `on_${string & keyof T}`]?: Key }) {} +//// +////fn(foo, { +//// /*1*/ +////}) +////fn({ a: "a", b: "b" }, { +//// /*2*/ +////}) + +verify.completions({ + marker: ["1", "2"], + exact: [ + { name: "on_a", sortText: completion.SortText.OptionalMember }, + { name: "on_b", sortText: completion.SortText.OptionalMember } + ] +});