generated from garronej/ts-ci
-
Notifications
You must be signed in to change notification settings - Fork 6
/
withDefaults.types.ts
108 lines (86 loc) 路 2.6 KB
/
withDefaults.types.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { assert } from "../assert.ts";
import { withDefaults } from "../withDefaults.ts";
import type { Equals } from "../Equals.ts";
const x: <T>() => T = null as any;
//@ts-ignore
function test<T, U, V>() {
const f: (params: { foo: T | undefined; bar: U }) => V = x<any>();
const got = withDefaults(f, { "foo": x<T>() });
const expected: (
params: {
bar: U;
} & {
defaultsOverwrite?: {
foo?: [T | undefined];
};
},
) => V = x<any>();
assert<Equals<typeof got, typeof expected>>();
}
//@ts-ignore
function test<T, U, V>() {
const f: (params: { foo: T; bar: U }) => V = x<any>();
const got = withDefaults(f, { "foo": x<T>() });
const expected: (
params: {
bar: U;
} & {
defaultsOverwrite?: {
foo?: [T];
};
},
) => V = x<any>();
assert<Equals<typeof got, typeof expected>>();
}
//@ts-ignore
function test<T, U, V>() {
const f: (params: { foo?: T; bar: U }) => V = x<any>();
const got = withDefaults(f, { "foo": x<T>() });
const expected: (
params: {
bar: U;
} & {
defaultsOverwrite?: {
foo?: [T | undefined];
};
},
) => V = x<any>();
assert<Equals<typeof got, typeof expected>>();
}
//@ts-ignore
function test<T>() {
// eslint-disable-next-line @typescript-eslint/ban-types
const f: (params: {}) => T = null as any;
//@ts-expect-error
withDefaults(f, { "foo": null as any });
}
//@ts-ignore
function test<T>() {
// eslint-disable-next-line @typescript-eslint/ban-types
const f: (params: { bar: number }) => T = null as any;
//@ts-expect-error
withDefaults(f, { "foo": null as any });
}
//@ts-ignore
function test<T>() {
// eslint-disable-next-line @typescript-eslint/ban-types
const f: (params: {}) => T = null as any;
withDefaults(f, {});
}
//@ts-ignore
function test<T>() {
// eslint-disable-next-line @typescript-eslint/ban-types
const f: (params: { foo: number; bar: string }) => T = null as any;
//@ts-expect-error
withDefaults(f, { "foo": null as any, "baz": "" });
}
//@ts-ignore
function test<T, U, V>() {
const f: (params: { a: U; b: T }) => V = x<any>();
const fWd = withDefaults(f, { "a": x<any>() });
//@ts-expect-error
const got = fWd({ "b": x<any>(), "defaultsOverwrite": { "a": [undefined] } });
}