Skip to content

Commit f3b118e

Browse files
authored
fix: filtering promise properties in object literal completion (#59316)
1 parent 09caaf6 commit f3b118e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/services/completions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5527,9 +5527,17 @@ function getJsDocTagAtPosition(node: Node, position: number): JSDocTag | undefin
55275527
/** @internal */
55285528
export function getPropertiesForObjectExpression(contextualType: Type, completionsType: Type | undefined, obj: ObjectLiteralExpression | JsxAttributes, checker: TypeChecker): Symbol[] {
55295529
const hasCompletionsType = completionsType && completionsType !== contextualType;
5530+
const promiseFilteredContextualType = checker.getUnionType(
5531+
filter(
5532+
contextualType.flags & TypeFlags.Union ?
5533+
(contextualType as UnionType).types :
5534+
[contextualType],
5535+
t => !checker.getPromisedTypeOfPromise(t),
5536+
),
5537+
);
55305538
const type = hasCompletionsType && !(completionsType.flags & TypeFlags.AnyOrUnknown)
5531-
? checker.getUnionType([contextualType, completionsType])
5532-
: contextualType;
5539+
? checker.getUnionType([promiseFilteredContextualType, completionsType])
5540+
: promiseFilteredContextualType;
55335541

55345542
const properties = getApparentProperties(type, obj, checker);
55355543
return type.isClass() && containsNonPublicProperties(properties) ? [] :
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="fourslash.ts" />
2+
// @strict: true
3+
4+
//// type MyType = {
5+
//// foo: string;
6+
//// };
7+
8+
//// function fakeTest(cb: () => MyType | Promise<MyType>) {}
9+
10+
//// fakeTest(() => {
11+
//// return {
12+
//// /*a*/
13+
//// };
14+
//// });
15+
16+
17+
verify.completions(
18+
{
19+
marker: ['a'],
20+
exact: [
21+
{ name: 'foo', kind: 'property' },
22+
]
23+
}
24+
);

0 commit comments

Comments
 (0)