Skip to content

Commit 73e58ea

Browse files
committed
Split tests
1 parent b00e6b5 commit 73e58ea

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21248,11 +21248,15 @@ namespace ts {
2124821248
type;
2124921249
}
2125021250

21251-
function getWidenedLiteralLikeTypeForContextualType(type: Type, contextualType: Type | undefined, contextNode?: Node) {
21252-
if (!isLiteralOfContextualType(type, contextualType) && !(contextNode && isLiteralOfContextualType(type, instantiateContextualType(contextualType, contextNode)))) {
21253-
type = getWidenedUniqueESSymbolType(getWidenedLiteralType(type));
21251+
function getWidenedLiteralLikeTypeForContextualType(type: Type, contextualType: Type | undefined, node?: Node) {
21252+
if (isLiteralOfContextualType(type, contextualType)) {
21253+
return type;
2125421254
}
21255-
return type;
21255+
const instantiatedContextualType = node && instantiateContextualType(contextualType, node) || contextualType;
21256+
if (instantiatedContextualType !== contextualType && isLiteralOfContextualType(type, instantiatedContextualType)) {
21257+
return type;
21258+
}
21259+
return getWidenedUniqueESSymbolType(getWidenedLiteralType(type));
2125621260
}
2125721261

2125821262
function getWidenedLiteralLikeTypeForContextualReturnTypeIfNeeded(type: Type | undefined, contextualSignatureReturnType: Type | undefined, isAsync: boolean) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
declare function f<T>(): T;
2+
const {} = f(); // error
3+
const { p1 } = f(); // error
4+
const [] = f(); // error
5+
const [e1, e2] = f(); // error
6+
7+
// Repro from #43605
8+
type Dispatch<A = { type: any; [extraProps: string]: any }> = { <T extends A>(action: T): T };
9+
type IFuncs = { readonly [key: string]: (...p: any) => void };
10+
type IDestructuring<T extends IFuncs> = { readonly [key in keyof T]?: (...p: Parameters<T[key]>) => void };
11+
type Destructuring<T extends IFuncs, U extends IDestructuring<T>> = (dispatch: Dispatch<any>, funcs: T) => U;
12+
const funcs1 = {
13+
funcA: (a: boolean): void => {},
14+
funcB: (b: string, bb: string): void => {},
15+
funcC: (c: number, cc: number, ccc: boolean): void => {},
16+
};
17+
type TFuncs1 = typeof funcs1;
18+
declare function useReduxDispatch1<T extends IDestructuring<TFuncs1>>(destructuring: Destructuring<TFuncs1, T>): T;
19+
const {} = useReduxDispatch1(
20+
(d, f) => ({
21+
funcA: (...p) => d(f.funcA(...p)), // p should be inferrable
22+
funcB: (...p) => d(f.funcB(...p)),
23+
funcC: (...p) => d(f.funcC(...p)),
24+
})
25+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare function pick<O, T extends keyof O>(keys: T[], obj?: O): Pick<O, T>;
2+
const _ = pick(['b'], { a: 'a', b: 'b' }); // T: "b"
3+
const { } = pick(['b'], { a: 'a', b: 'b' }); // T: "b" | "a" ??? (before fix)
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,2 @@
1-
declare function f2<T>(cb: () => T): T;
2-
const [e1, e2, e3] = f2(() => [1, "hi", true]);
3-
4-
declare function f1<T>(): T;
5-
const {} = f1(); // error
6-
const { p1 } = f1(); // error
7-
8-
declare function pick<O, T extends keyof O>(keys: T[], obj?: O): Pick<O, T>;
9-
const _ = pick(['b'], { a: 'a', b: 'b' }); // T: "b"
10-
const { } = pick(['b'], { a: 'a', b: 'b' }); // T: "b" | "a" ???
11-
12-
type Dispatch<A = { type: any; [extraProps: string]: any }> = { <T extends A>(action: T): T };
13-
type IFuncs = { readonly [key: string]: (...p: any) => void };
14-
type IDestructuring<T extends IFuncs> = { readonly [key in keyof T]?: (...p: Parameters<T[key]>) => void };
15-
type Destructuring<T extends IFuncs, U extends IDestructuring<T>> = (dispatch: Dispatch<any>, funcs: T) => U;
16-
const funcs1 = {
17-
funcA: (a: boolean): void => {},
18-
funcB: (b: string, bb: string): void => {},
19-
funcC: (c: number, cc: number, ccc: boolean): void => {},
20-
};
21-
type TFuncs1 = typeof funcs1;
22-
declare function useReduxDispatch1<T extends IDestructuring<TFuncs1>>(destructuring: Destructuring<TFuncs1, T>): T;
23-
const {} = useReduxDispatch1(
24-
(d, f) => ({
25-
funcA: (...p) => d(f.funcA(...p)),
26-
funcB: (...p) => d(f.funcB(...p)),
27-
funcC: (...p) => d(f.funcC(...p))
28-
})
29-
);
1+
declare function f<T>(cb: () => T): T;
2+
const [e1, e2, e3] = f(() => [1, "hi", true]);

0 commit comments

Comments
 (0)