From 4d7ec380a9a5d6f7e2f882d6bae9557d7414afb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Tue, 26 Feb 2019 10:54:01 +0800 Subject: [PATCH] check completions with assignable rather than identity --- src/compiler/checker.ts | 2 +- .../completionsWithOptionalProperties.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsWithOptionalProperties.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ddc958df0b4..c882227ba0c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7406,7 +7406,7 @@ namespace ts { const nameType = property.name && getLiteralTypeFromPropertyName(property.name); const name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined; const expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name); - return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected); + return !!expected && isLiteralType(expected) && !isTypeAssignableTo(getTypeOfNode(property), expected); }); } diff --git a/tests/cases/fourslash/completionsWithOptionalProperties.ts b/tests/cases/fourslash/completionsWithOptionalProperties.ts new file mode 100644 index 00000000000..e40029ddefa --- /dev/null +++ b/tests/cases/fourslash/completionsWithOptionalProperties.ts @@ -0,0 +1,18 @@ +/// +// @strict: true + +//// interface Options { +//// hello?: boolean; +//// world?: boolean; +//// } +//// declare function foo(options?: Options): void; +//// foo({ +//// hello: true, +//// /**/ +//// }); + +verify.completions({ + marker: "", + includes: ['world'] +}); +