mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-06 23:59:42 -05:00
Merge pull request #30094 from Kingwl/improve_completions_for_optional_props
check completions with assignable rather than identity
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
18
tests/cases/fourslash/completionsWithOptionalProperties.ts
Normal file
18
tests/cases/fourslash/completionsWithOptionalProperties.ts
Normal 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']
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user