Skip to content

Commit 5f94aae

Browse files
committed
Weird fix
1 parent 87cc8c4 commit 5f94aae

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
@@ -20983,7 +20983,16 @@ namespace ts {
2098320983
}
2098420984
if (contextFlags && contextFlags & ContextFlags.Completion && signature.target) {
2098520985
const baseSignature = getBaseSignature(signature.target);
20986-
return intersectTypes(getTypeAtPosition(signature, argIndex), getTypeAtPosition(baseSignature, argIndex));
20986+
// Only consider the type from the base signature for completions
20987+
// if it actually contributes something. The type from the contextually
20988+
// instantiated signature is the _real_ type anyway, so we should never
20989+
// let the base type _remove_ completions from the list.
20990+
const baseArgumentType = filterType(
20991+
getTypeAtPosition(baseSignature, argIndex),
20992+
t => !(t.flags & (TypeFlags.AnyOrUnknown | TypeFlags.IndexedAccess)));
20993+
if (!(baseArgumentType.flags & TypeFlags.Never)) {
20994+
return intersectTypes(getTypeAtPosition(signature, argIndex), baseArgumentType);
20995+
}
2098720996
}
2098820997
return getTypeAtPosition(signature, argIndex);
2098920998
}
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)