-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-medium-return-type.ts
24 lines (20 loc) · 817 Bytes
/
2-medium-return-type.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ============= Test Cases =============
import type { Equal, Expect } from "./2-return-type/test-utils";
type cases = [
Expect<Equal<string, MyReturnType<() => string>>>,
Expect<Equal<123, MyReturnType<() => 123>>>,
Expect<Equal<ComplexObject, MyReturnType<() => ComplexObject>>>,
Expect<Equal<Promise<boolean>, MyReturnType<() => Promise<boolean>>>>,
Expect<Equal<() => "foo", MyReturnType<() => () => "foo">>>,
Expect<Equal<1 | 2, MyReturnType<typeof fn>>>,
Expect<Equal<1 | 2, MyReturnType<typeof fn1>>>
];
type ComplexObject = {
a: [12, "foo"];
bar: "hello";
prev(): number;
};
const fn = (v: boolean) => (v ? 1 : 2);
const fn1 = (v: boolean, w: any) => (v ? 1 : 2);
// ============= Your Code Here =============
type MyReturnType<T> = T extends (...args: any[]) => infer R ? R : never;