Merge pull request #30094 from Kingwl/improve_completions_for_optional_props

check completions with assignable rather than identity
This commit is contained in:
Daniel Rosenwasser
2019-02-26 16:19:50 -08:00
committed by GitHub
2 changed files with 19 additions and 1 deletions

View File

@@ -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);
});
}

View File

@@ -0,0 +1,18 @@
/// <reference path="fourslash.ts" />
// @strict: true
//// interface Options {
//// hello?: boolean;
//// world?: boolean;
//// }
//// declare function foo(options?: Options): void;
//// foo({
//// hello: true,
//// /**/
//// });
verify.completions({
marker: "",
includes: ['world']
});