diff --git a/src/services/completions.ts b/src/services/completions.ts index d240cacc2c3c3..cf3f1cdf39efa 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -5472,9 +5472,17 @@ function getJsDocTagAtPosition(node: Node, position: number): JSDocTag | undefin /** @internal */ export function getPropertiesForObjectExpression(contextualType: Type, completionsType: Type | undefined, obj: ObjectLiteralExpression | JsxAttributes, checker: TypeChecker): Symbol[] { const hasCompletionsType = completionsType && completionsType !== contextualType; + const promiseFilteredContextualType = checker.getUnionType( + filter( + contextualType.flags & TypeFlags.Union ? + (contextualType as UnionType).types : + [contextualType], + t => !checker.getPromisedTypeOfPromise(t), + ), + ); const type = hasCompletionsType && !(completionsType.flags & TypeFlags.AnyOrUnknown) - ? checker.getUnionType([contextualType, completionsType]) - : contextualType; + ? checker.getUnionType([promiseFilteredContextualType, completionsType]) + : promiseFilteredContextualType; const properties = getApparentProperties(type, obj, checker); return type.isClass() && containsNonPublicProperties(properties) ? [] : diff --git a/tests/cases/fourslash/completionsPropertiesWithPromiseUnionType.ts b/tests/cases/fourslash/completionsPropertiesWithPromiseUnionType.ts new file mode 100644 index 0000000000000..529160b6589b9 --- /dev/null +++ b/tests/cases/fourslash/completionsPropertiesWithPromiseUnionType.ts @@ -0,0 +1,24 @@ +/// +// @strict: true + +//// type MyType = { +//// foo: string; +//// }; + +//// function fakeTest(cb: () => MyType | Promise) {} + +//// fakeTest(() => { +//// return { +//// /*a*/ +//// }; +//// }); + + +verify.completions( + { + marker: ['a'], + exact: [ + { name: 'foo', kind: 'property' }, + ] + } +); \ No newline at end of file