diff --git a/src/services/completions.ts b/src/services/completions.ts index e8ff98ea7a0db..9b93db8ab6a40 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2595,7 +2595,7 @@ function getContextualType(previousToken: Node, position: number, sourceFile: So isEqualityOperatorKind(previousToken.kind) && isBinaryExpression(parent) && isEqualityOperatorKind(parent.operatorToken.kind) ? // completion at `x ===/**/` should be for the right side checker.getTypeAtLocation(parent.left) : - checker.getContextualType(previousToken as Expression); + checker.getContextualType(previousToken as Expression, ContextFlags.Completions) || checker.getContextualType(previousToken as Expression); } } diff --git a/tests/cases/fourslash/completionEntryForArgumentConstrainedToString.ts b/tests/cases/fourslash/completionEntryForArgumentConstrainedToString.ts new file mode 100644 index 0000000000000..49eb853a37d0a --- /dev/null +++ b/tests/cases/fourslash/completionEntryForArgumentConstrainedToString.ts @@ -0,0 +1,8 @@ +/// + +//// declare function test

(p: P): void; +//// +//// test(/*ts*/) +//// + +verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: true }); diff --git a/tests/cases/fourslash/completionEntryForArrayElementConstrainedToString.ts b/tests/cases/fourslash/completionEntryForArrayElementConstrainedToString.ts new file mode 100644 index 0000000000000..41778c5089f90 --- /dev/null +++ b/tests/cases/fourslash/completionEntryForArrayElementConstrainedToString.ts @@ -0,0 +1,7 @@ +/// + +//// declare function test(a: { foo: T[] }): void +//// +//// test({ foo: [/*ts*/] }) + +verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: true }); diff --git a/tests/cases/fourslash/completionEntryForArrayElementConstrainedToString2.ts b/tests/cases/fourslash/completionEntryForArrayElementConstrainedToString2.ts new file mode 100644 index 0000000000000..a3eddacb5da6b --- /dev/null +++ b/tests/cases/fourslash/completionEntryForArrayElementConstrainedToString2.ts @@ -0,0 +1,7 @@ +/// + +//// declare function test(a: { foo: T[] }): void +//// +//// test({ foo: ['a', /*ts*/] }) + +verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: true }); diff --git a/tests/cases/fourslash/completionEntryForPropertyConstrainedToString.ts b/tests/cases/fourslash/completionEntryForPropertyConstrainedToString.ts new file mode 100644 index 0000000000000..f2d9b7270673f --- /dev/null +++ b/tests/cases/fourslash/completionEntryForPropertyConstrainedToString.ts @@ -0,0 +1,7 @@ +/// + +//// declare function test

(p: { type: P }): void; +//// +//// test({ type: /*ts*/ }) + +verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: false }); diff --git a/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType1.ts b/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType1.ts index 8e2550d1a57a3..584ea46b6ed90 100644 --- a/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType1.ts +++ b/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType1.ts @@ -13,5 +13,13 @@ //// b: "/*ts*/", //// }, //// }); +//// +//// test({ +//// foo: {}, +//// bar: { +//// b: /*ts2*/, +//// }, +//// }); verify.completions({ marker: ["ts"], exact: ["foo", "bar"] }); +verify.completions({ marker: ["ts2"], includes: ['"foo"', '"bar"'], isNewIdentifierLocation: false }); diff --git a/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType3.ts b/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType3.ts index 9cbe1777324d0..dfb4417cf8a01 100644 --- a/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType3.ts +++ b/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType3.ts @@ -12,5 +12,13 @@ //// b: ["/*ts*/"], //// }, //// }); +//// +//// test({ +//// foo: {}, +//// bar: { +//// b: [/*ts2*/], +//// }, +//// }); verify.completions({ marker: ["ts"], exact: ["foo", "bar"] }); +verify.completions({ marker: ["ts2"], includes: ['"foo"', '"bar"'], isNewIdentifierLocation: true });