generated from garronej/ts-ci
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Params0.ts
80 lines (62 loc) 路 1.45 KB
/
Params0.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import type { Param0 } from "../Param0.ts";
import { assert } from "../assert.ts";
import type { Equals } from "../Equals.ts";
//@ts-ignore
function test<T, U>() {
const f = (params: { foo: T; bar: U }) => {
return params;
};
type Expected = {
foo: T;
bar: U;
};
type Got = Param0<typeof f>;
assert<Equals<Got, Expected>>();
}
//@ts-ignore
function test<T, U>() {
const f = (params: { foo: T; bar: U }, a: unknown, b: unknown) => {
return {
...params,
a,
b,
};
};
type Expected = {
foo: T;
bar: U;
};
type Got = Param0<typeof f>;
assert<Equals<Got, Expected>>();
}
{
//@ts-expect-error
type Got = Params<string>;
}
{
class A {
foo: number;
constructor(foo: number) {
this.foo = foo;
}
}
//@ts-expect-error
type Got = Params<A>;
}
{
type Got = Param0<undefined | null | false | "">;
type Expected = never;
assert<Equals<Got, Expected>>();
}
{
type Got = Param0<((params: { foo: string }) => void) | undefined | null | false | "">;
type Expected = { foo: string };
assert<Equals<Got, Expected>>();
}
{
type Got = Param0<(() => void) | undefined | null | false | "">;
type Expected = void;
assert<Equals<Got, Expected>>();
}