Skip to content

Commit 5762387

Browse files
committed
Weird fix
1 parent 7c14aff commit 5762387

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21162,7 +21162,16 @@ namespace ts {
2116221162
}
2116321163
if (contextFlags && contextFlags & ContextFlags.Completion && signature.target) {
2116421164
const baseSignature = getBaseSignature(signature.target);
21165-
return intersectTypes(getTypeAtPosition(signature, argIndex), getTypeAtPosition(baseSignature, argIndex));
21165+
// Only consider the type from the base signature for completions
21166+
// if it actually contributes something. The type from the contextually
21167+
// instantiated signature is the _real_ type anyway, so we should never
21168+
// let the base type _remove_ completions from the list.
21169+
const baseArgumentType = filterType(
21170+
getTypeAtPosition(baseSignature, argIndex),
21171+
t => !(t.flags & (TypeFlags.AnyOrUnknown | TypeFlags.IndexedAccess)));
21172+
if (!(baseArgumentType.flags & TypeFlags.Never)) {
21173+
return intersectTypes(getTypeAtPosition(signature, argIndex), baseArgumentType);
21174+
}
2116621175
}
2116721176
return getTypeAtPosition(signature, argIndex);
2116821177
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// #34825
4+
5+
////interface Sample {
6+
//// addBook: { name: string, year: number }
7+
////}
8+
////
9+
////export declare function testIt<T>(method: T[keyof T]): any
10+
////testIt<Sample>({ /**/ });
11+
12+
verify.completions({
13+
marker: '',
14+
exact: [
15+
{ name: 'name' },
16+
{ name: 'year' },
17+
]
18+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// #34825
4+
5+
////export type GetMethodsForType<T, G extends string> = { [K in keyof T]:
6+
//// T[K] extends () => any ? { name: K, group: G, } : T[K] extends (s: infer U) => any ? { name: K, group: G, payload: U } : never }[keyof T];
7+
////
8+
////
9+
////class Sample {
10+
//// count = 0;
11+
//// books: { name: string, year: number }[] = []
12+
//// increment() {
13+
//// this.count++
14+
//// this.count++
15+
//// }
16+
////
17+
//// addBook(book: Sample["books"][0]) {
18+
//// this.books.push(book)
19+
//// }
20+
////}
21+
////export declare function testIt<T, G extends string>(): (input: any, method: GetMethodsForType<T, G>) => any
22+
////
23+
////
24+
////const t = testIt<Sample, "Sample">()
25+
////
26+
////const i = t(null, { name: "addBook", group: "Sample", payload: { /**/ } })
27+
28+
verify.completions({
29+
marker: '',
30+
exact: [
31+
{ name: 'name' },
32+
{ name: 'year' },
33+
]
34+
});

0 commit comments

Comments
 (0)