fix: filtering promise properties in object literal completion (#59316)
This commit is contained in:
Родитель
09caaf60aa
Коммит
f3b118ed21
|
@ -5527,9 +5527,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) ? [] :
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
// @strict: true
|
||||
|
||||
//// type MyType = {
|
||||
//// foo: string;
|
||||
//// };
|
||||
|
||||
//// function fakeTest(cb: () => MyType | Promise<MyType>) {}
|
||||
|
||||
//// fakeTest(() => {
|
||||
//// return {
|
||||
//// /*a*/
|
||||
//// };
|
||||
//// });
|
||||
|
||||
|
||||
verify.completions(
|
||||
{
|
||||
marker: ['a'],
|
||||
exact: [
|
||||
{ name: 'foo', kind: 'property' },
|
||||
]
|
||||
}
|
||||
);
|
Загрузка…
Ссылка в новой задаче