@layerzerolabs/typescript-utils 0.2.68 → 0.2.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/typescript-utils",
3
- "version": "0.2.68",
3
+ "version": "0.2.70",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,11 +13,14 @@
13
13
  "main": "./dist/index.cjs",
14
14
  "module": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist/**/*"
18
+ ],
16
19
  "devDependencies": {
17
20
  "tsup": "^8.4.0",
18
21
  "vitest": "^3.2.3",
19
- "@layerzerolabs/tsup-configuration": "0.2.68",
20
- "@layerzerolabs/typescript-configuration": "0.2.68"
22
+ "@layerzerolabs/tsup-configuration": "0.2.70",
23
+ "@layerzerolabs/typescript-configuration": "0.2.70"
21
24
  },
22
25
  "publishConfig": {
23
26
  "access": "public",
@@ -1,178 +0,0 @@
1
-  WARN  Issue while reading "/home/runner/work/monorepo-internal/monorepo-internal/.npmrc". Failed to replace env in config: ${NPM_TOKEN}
2
-
3
- > @layerzerolabs/typescript-utils@0.0.0 build /home/runner/work/monorepo-internal/monorepo-internal/packages/typescript-utils
4
- > tsup
5
-
6
- CLI Building entry: src/advancedRecord.ts, src/asyncify.ts, src/branded.ts, src/constructor.ts, src/deep.test-d.ts, src/deep.ts, src/disallowedAny.ts, src/identity.ts, src/index.ts, src/lastOf.ts, src/maybeUndefined.ts, src/merge.ts, src/methodOf.ts, src/removeNever.ts, src/strings.test-d.ts, src/strings.ts, src/tuples.ts, src/valueOf.ts, src/viem.ts, src/withRequired.ts
7
- CLI Using tsconfig: tsconfig.json
8
- CLI tsup v8.5.1
9
- CLI Using tsup config: /home/runner/work/monorepo-internal/monorepo-internal/packages/typescript-utils/tsup.config.ts
10
- CLI Target: ES2023
11
- CLI Cleaning output folder
12
- CJS Build start
13
- ESM Build start
14
- Entry module "dist/EUBM3LSR.cjs" is using named and default exports together. Consumers of your bundle will have to use `chunk.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.
15
- "default" is imported from external module "path" but never used in "dist/6AHA7PAZ.js".
16
- "fileURLToPath" is imported from external module "url" but never used in "dist/6AHA7PAZ.js".
17
- CJS dist/valueOf.cjs 143.00 B
18
- CJS dist/withRequired.cjs 153.00 B
19
- CJS dist/index.cjs 639.00 B
20
- CJS dist/viem.cjs 137.00 B
21
- CJS dist/KQUDWU4T.cjs 187.00 B
22
- CJS dist/tuples.cjs 141.00 B
23
- CJS dist/2MZ52QXI.cjs 188.00 B
24
- CJS dist/EUBM3LSR.cjs 42.53 KB
25
- CJS dist/B4TXK443.cjs 185.00 B
26
- CJS dist/4W25K7RR.cjs 193.00 B
27
- CJS dist/lastOf.cjs 141.00 B
28
- CJS dist/2OSBYVBM.cjs 187.00 B
29
- CJS dist/7RPBI4LQ.cjs 195.00 B
30
- CJS dist/maybeUndefined.cjs 157.00 B
31
- CJS dist/merge.cjs 139.00 B
32
- CJS dist/AKBGASRF.cjs 186.00 B
33
- CJS dist/methodOf.cjs 145.00 B
34
- CJS dist/removeNever.cjs 151.00 B
35
- CJS dist/NKWLAYNJ.cjs 189.00 B
36
- CJS dist/K3FZ3EZT.cjs 188.00 B
37
- CJS dist/strings.cjs 143.00 B
38
- CJS dist/Q35ZNXMT.cjs 192.00 B
39
- CJS dist/advancedRecord.cjs 157.00 B
40
- CJS dist/C7GMKBCN.cjs 195.00 B
41
- CJS dist/asyncify.cjs 145.00 B
42
- CJS dist/strings.test-d.cjs 893.00 B
43
- CJS dist/WPET3HPL.cjs 189.00 B
44
- CJS dist/53OHF4EH.cjs 192.00 B
45
- CJS dist/branded.cjs 143.00 B
46
- CJS dist/2SJJDCZI.cjs 188.00 B
47
- CJS dist/constructor.cjs 151.00 B
48
- CJS dist/deep.test-d.cjs 574.00 B
49
- CJS dist/deep.cjs 137.00 B
50
- CJS dist/MLSONTXK.cjs 185.00 B
51
- CJS dist/disallowedAny.cjs 155.00 B
52
- CJS dist/574X5FJM.cjs 194.00 B
53
- CJS dist/identity.cjs 145.00 B
54
- CJS dist/TVCGTTL5.cjs 189.00 B
55
- CJS dist/24WEKBY3.cjs 2.10 KB
56
- CJS dist/QXEVXGNQ.cjs 301.19 KB
57
- CJS dist/valueOf.cjs.map 72.00 B
58
- CJS dist/withRequired.cjs.map 77.00 B
59
- CJS dist/index.cjs.map 665.00 B
60
- CJS dist/tuples.cjs.map 71.00 B
61
- CJS dist/KQUDWU4T.cjs.map 2.68 KB
62
- CJS dist/2MZ52QXI.cjs.map 538.00 B
63
- CJS dist/viem.cjs.map 69.00 B
64
- CJS dist/B4TXK443.cjs.map 8.26 KB
65
- CJS dist/EUBM3LSR.cjs.map 100.19 KB
66
- CJS dist/4W25K7RR.cjs.map 299.00 B
67
- CJS dist/lastOf.cjs.map 71.00 B
68
- CJS dist/7RPBI4LQ.cjs.map 642.00 B
69
- CJS dist/2OSBYVBM.cjs.map 659.00 B
70
- CJS dist/maybeUndefined.cjs.map 79.00 B
71
- CJS dist/merge.cjs.map 70.00 B
72
- CJS dist/AKBGASRF.cjs.map 469.00 B
73
- CJS dist/methodOf.cjs.map 73.00 B
74
- CJS dist/removeNever.cjs.map 76.00 B
75
- CJS dist/strings.cjs.map 72.00 B
76
- CJS dist/NKWLAYNJ.cjs.map 399.00 B
77
- CJS dist/Q35ZNXMT.cjs.map 252.00 B
78
- CJS dist/K3FZ3EZT.cjs.map 1.42 KB
79
- CJS dist/C7GMKBCN.cjs.map 906.00 B
80
- CJS dist/advancedRecord.cjs.map 79.00 B
81
- CJS dist/WPET3HPL.cjs.map 341.00 B
82
- CJS dist/53OHF4EH.cjs.map 214.00 B
83
- CJS dist/asyncify.cjs.map 73.00 B
84
- CJS dist/2SJJDCZI.cjs.map 719.00 B
85
- CJS dist/deep.test-d.cjs.map 1.47 KB
86
- CJS dist/deep.cjs.map 69.00 B
87
- CJS dist/constructor.cjs.map 76.00 B
88
- CJS dist/branded.cjs.map 72.00 B
89
- CJS dist/identity.cjs.map 73.00 B
90
- CJS dist/24WEKBY3.cjs.map 923.00 B
91
- CJS dist/TVCGTTL5.cjs.map 265.00 B
92
- CJS dist/MLSONTXK.cjs.map 780.00 B
93
- CJS dist/disallowedAny.cjs.map 78.00 B
94
- CJS dist/574X5FJM.cjs.map 390.00 B
95
- CJS dist/strings.test-d.cjs.map 1.70 KB
96
- CJS dist/QXEVXGNQ.cjs.map 762.74 KB
97
- CJS ⚡️ Build success in 2406ms
98
- ESM dist/tuples.js 117.00 B
99
- ESM dist/valueOf.js 119.00 B
100
- ESM dist/viem.js 113.00 B
101
- ESM dist/withRequired.js 129.00 B
102
- ESM dist/GGKJNPTT.js 42.15 KB
103
- ESM dist/TQNP6GIE.js 158.00 B
104
- ESM dist/index.js 558.00 B
105
- ESM dist/EM7SXG4B.js 157.00 B
106
- ESM dist/62TVLGZP.js 163.00 B
107
- ESM dist/J7BAXUWJ.js 155.00 B
108
- ESM dist/KZQATXOW.js 157.00 B
109
- ESM dist/lastOf.js 117.00 B
110
- ESM dist/maybeUndefined.js 133.00 B
111
- ESM dist/merge.js 115.00 B
112
- ESM dist/Q6UBIYTZ.js 165.00 B
113
- ESM dist/DDDCRYAA.js 156.00 B
114
- ESM dist/methodOf.js 121.00 B
115
- ESM dist/KEJFF7VD.js 159.00 B
116
- ESM dist/removeNever.js 127.00 B
117
- ESM dist/I5NXBMAF.js 162.00 B
118
- ESM dist/strings.test-d.js 745.00 B
119
- ESM dist/strings.js 119.00 B
120
- ESM dist/CFTTK4D6.js 165.00 B
121
- ESM dist/advancedRecord.js 133.00 B
122
- ESM dist/B5GSIBEU.js 158.00 B
123
- ESM dist/asyncify.js 121.00 B
124
- ESM dist/TP4DJK6G.js 159.00 B
125
- ESM dist/6IUBP3YE.js 158.00 B
126
- ESM dist/constructor.js 127.00 B
127
- ESM dist/deep.test-d.js 491.00 B
128
- ESM dist/branded.js 119.00 B
129
- ESM dist/deep.js 113.00 B
130
- ESM dist/X6GYSLZB.js 162.00 B
131
- ESM dist/FQ2L5NQU.js 155.00 B
132
- ESM dist/V353KAGF.js 164.00 B
133
- ESM dist/disallowedAny.js 131.00 B
134
- ESM dist/identity.js 121.00 B
135
- ESM dist/P3JODCMF.js 159.00 B
136
- ESM dist/6AHA7PAZ.js 1.87 KB
137
- ESM dist/QDQO2ODJ.js 295.28 KB
138
- ESM dist/tuples.js.map 70.00 B
139
- ESM dist/viem.js.map 68.00 B
140
- ESM dist/valueOf.js.map 71.00 B
141
- ESM dist/withRequired.js.map 76.00 B
142
- ESM dist/GGKJNPTT.js.map 100.16 KB
143
- ESM dist/TQNP6GIE.js.map 517.00 B
144
- ESM dist/index.js.map 644.00 B
145
- ESM dist/EM7SXG4B.js.map 2.66 KB
146
- ESM dist/62TVLGZP.js.map 278.00 B
147
- ESM dist/KZQATXOW.js.map 638.00 B
148
- ESM dist/lastOf.js.map 70.00 B
149
- ESM dist/J7BAXUWJ.js.map 8.24 KB
150
- ESM dist/maybeUndefined.js.map 78.00 B
151
- ESM dist/Q6UBIYTZ.js.map 621.00 B
152
- ESM dist/merge.js.map 69.00 B
153
- ESM dist/DDDCRYAA.js.map 448.00 B
154
- ESM dist/methodOf.js.map 72.00 B
155
- ESM dist/KEJFF7VD.js.map 378.00 B
156
- ESM dist/removeNever.js.map 75.00 B
157
- ESM dist/I5NXBMAF.js.map 231.00 B
158
- ESM dist/strings.test-d.js.map 1.68 KB
159
- ESM dist/strings.js.map 71.00 B
160
- ESM dist/CFTTK4D6.js.map 885.00 B
161
- ESM dist/advancedRecord.js.map 78.00 B
162
- ESM dist/asyncify.js.map 72.00 B
163
- ESM dist/TP4DJK6G.js.map 320.00 B
164
- ESM dist/B5GSIBEU.js.map 1.40 KB
165
- ESM dist/6IUBP3YE.js.map 698.00 B
166
- ESM dist/constructor.js.map 75.00 B
167
- ESM dist/deep.test-d.js.map 1.45 KB
168
- ESM dist/deep.js.map 68.00 B
169
- ESM dist/branded.js.map 71.00 B
170
- ESM dist/X6GYSLZB.js.map 193.00 B
171
- ESM dist/FQ2L5NQU.js.map 759.00 B
172
- ESM dist/V353KAGF.js.map 369.00 B
173
- ESM dist/identity.js.map 72.00 B
174
- ESM dist/disallowedAny.js.map 77.00 B
175
- ESM dist/P3JODCMF.js.map 244.00 B
176
- ESM dist/6AHA7PAZ.js.map 666.00 B
177
- ESM dist/QDQO2ODJ.js.map 761.96 KB
178
- ESM ⚡️ Build success in 2409ms
@@ -1,8 +0,0 @@
1
-
2
- > @layerzerolabs/typescript-utils@0.0.0 lint /home/runner/work/monorepo-internal/monorepo-internal/packages/typescript-utils
3
- > eslint . --max-warnings 0 || (eslint . --fix --max-warnings 0 && false)
4
-
5
- (node:67741) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1775694520701 is not specified and it doesn't parse as CommonJS.
6
- Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
7
- To eliminate this warning, add "type": "module" to /home/runner/work/monorepo-internal/monorepo-internal/package.json.
8
- (Use `node --trace-warnings ...` to show where the warning was created)
@@ -1,23 +0,0 @@
1
- export type AdvancedRecord<T = any, U = any> = {
2
- readonly [key: string]: readonly [T, U];
3
- };
4
-
5
- export type DeepWritable<T> = { -readonly [P in keyof T]: DeepWritable<T[P]> };
6
-
7
- export type AdvancedRecordLookup<
8
- AR extends AdvancedRecord | undefined,
9
- KeyToFind,
10
- > = AR extends AdvancedRecord
11
- ? {
12
- [P in keyof AR]: AR[P] extends readonly [infer K, infer V]
13
- ? // Distribute on K
14
- K extends unknown
15
- ? KeyToFind extends DeepWritable<K>
16
- ? V
17
- : DeepWritable<K> extends KeyToFind
18
- ? V
19
- : never
20
- : never
21
- : never;
22
- }[keyof AR]
23
- : never;
package/src/asyncify.ts DELETED
@@ -1,5 +0,0 @@
1
- export type AsyncifyDeep<T> = T extends (...args: infer A) => infer R
2
- ? (...args: A) => Promise<R>
3
- : T extends object
4
- ? { [K in keyof T]: AsyncifyDeep<T[K]> }
5
- : T;
package/src/branded.ts DELETED
@@ -1,19 +0,0 @@
1
- const tag = '___tag___';
2
- /**
3
- * Creates a branded type of {@link T} with the brand {@link U}.
4
- *
5
- * @param T - Type to brand
6
- * @param U - Label
7
- * @returns Branded type
8
- *
9
- * @example
10
- * type Result = Branded<string, 'foo'>
11
- * // ^? type Result = string & { [symbol]: 'foo' }
12
- */
13
- export type Branded<T, U> = T & { [tag]: U };
14
- /**
15
- * Represents a percentage as a decimal value. For example, 25% is represented as 0.25
16
- */
17
- export type Percent = number; // Branded<number, 'percent'>
18
-
19
- export type BrandedError<T extends string> = Branded<Error, T>;
@@ -1 +0,0 @@
1
- export type Constructor<T> = { new (...args: any[]): T };
@@ -1,33 +0,0 @@
1
- import { expectTypeOf, test } from 'vitest';
2
-
3
- import type { Branded } from './branded';
4
- import type { DeepOptional } from './deep';
5
-
6
- test('DeepOptional', () => {
7
- // 1 level
8
- type A = DeepOptional<{ a: string; b: number }>;
9
- expectTypeOf<A>().toEqualTypeOf<{ a?: string; b?: number }>();
10
-
11
- // 2 levels
12
- type B = DeepOptional<{ a: { c: string }; b: number }>;
13
- expectTypeOf<B>().toEqualTypeOf<{ a?: { c?: string }; b?: number }>();
14
-
15
- // 1 level with brand tag
16
- type obj = { a: string; b: number };
17
- type branded = Branded<obj, 'foo'>;
18
- type C = DeepOptional<branded>;
19
- expectTypeOf<C>().toEqualTypeOf<{ a?: string; b?: number; ___tag___: 'foo' }>();
20
-
21
- // 2 levels with brand tag
22
- type obj2 = { a: branded; b: number };
23
- type D = DeepOptional<Branded<obj2, 'foo2'>>;
24
- expectTypeOf<D>().toEqualTypeOf<{
25
- a?: {
26
- a?: string;
27
- b?: number;
28
- ___tag___: 'foo';
29
- };
30
- b?: number;
31
- ___tag___: 'foo2';
32
- }>();
33
- });
package/src/deep.ts DELETED
@@ -1,26 +0,0 @@
1
- import type { Prettify } from './viem';
2
-
3
- /**
4
- * Copy the brand tag from the branded.ts file, can't import it to keep it hidden from library users
5
- */
6
- const brandTag = '___tag___';
7
-
8
- export type DeepRequire<T> = {
9
- [P in keyof T]-?: DeepRequire<T[P]>;
10
- };
11
-
12
- export type DeepOptional<T> = T extends { [brandTag]: infer V }
13
- ? Prettify<
14
- { [brandTag]: V } & {
15
- [P in keyof T]?: DeepOptional<T[P]>;
16
- }
17
- >
18
- : {
19
- [P in keyof T]?: DeepOptional<T[P]>;
20
- };
21
-
22
- export type DeepUnion<T, U> =
23
- | {
24
- [P in keyof T]: DeepUnion<T[P], U>;
25
- }
26
- | U;
@@ -1,5 +0,0 @@
1
- type IsAnyInner<T> = T extends never ? true : false;
2
-
3
- export type IsAny<T> =
4
- IsAnyInner<T> extends true ? false : IsAnyInner<T> extends false ? false : true;
5
- export type DisallowedAny<T> = IsAny<T> extends true ? never : T;
package/src/identity.ts DELETED
@@ -1,2 +0,0 @@
1
- // Wraps types and property access with 1-arity which enables creating interfaces
2
- export type Identity<T> = T;
package/src/index.ts DELETED
@@ -1,17 +0,0 @@
1
- export * from './advancedRecord';
2
- export * from './asyncify';
3
- export * from './branded';
4
- export * from './constructor';
5
- export * from './deep';
6
- export * from './disallowedAny';
7
- export * from './identity';
8
- export * from './lastOf';
9
- export * from './maybeUndefined';
10
- export * from './merge';
11
- export * from './methodOf';
12
- export * from './removeNever';
13
- export * from './strings';
14
- export * from './tuples';
15
- export * from './valueOf';
16
- export * from './viem';
17
- export * from './withRequired';
package/src/lastOf.ts DELETED
@@ -1,15 +0,0 @@
1
- export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
2
- k: infer I,
3
- ) => void
4
- ? I
5
- : never;
6
-
7
- export type LastOf<T> =
8
- UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
9
-
10
- type Prepend<T, U extends any[]> = [T, ...U];
11
-
12
- export type UnionToArray<T, U extends any[] = []> =
13
- LastOf<T> extends never ? U : UnionToArray<Exclude<T, LastOf<T>>, Prepend<LastOf<T>, U>>;
14
-
15
- export type RestOf<T> = Exclude<T, LastOf<T>>;
@@ -1,16 +0,0 @@
1
- /**
2
- * @description Maps the result type `R` to `R | undefined` when the input type `T` includes `undefined`,
3
- * preserving the undefined-ness of the input in the output type.
4
- *
5
- * @example
6
- * MaybeUndefinedMapped<string | undefined, number>
7
- * => number | undefined
8
- *
9
- * MaybeUndefinedMapped<string, number>
10
- * => number
11
- */
12
- export type MaybeUndefinedMapped<T, R> = undefined extends T
13
- ? T extends undefined
14
- ? undefined
15
- : R | undefined
16
- : R;
package/src/merge.ts DELETED
@@ -1,13 +0,0 @@
1
- import type { Prettify } from './viem';
2
-
3
- export type Merge<T, U> = {} extends T
4
- ? U
5
- : {} extends U
6
- ? T
7
- : Prettify<
8
- {
9
- [key in keyof T]: key extends keyof U ? U[key] : T[key];
10
- } & {
11
- [key in keyof U]: U[key];
12
- }
13
- >;
package/src/methodOf.ts DELETED
@@ -1,7 +0,0 @@
1
- export type MethodOf<T> = {
2
- [key in keyof T]: T[key] extends (...args: any[]) => any ? T[key] : never;
3
- }[keyof T];
4
-
5
- export type MethodNameOf<T> = {
6
- [key in keyof T]: T[key] extends (...args: any[]) => any ? key : never;
7
- }[keyof T];
@@ -1,3 +0,0 @@
1
- export type RemoveNever<T> = {
2
- [K in keyof T as T[K] extends never ? never : K]: T[K];
3
- };
@@ -1,32 +0,0 @@
1
- import { expectTypeOf, test } from 'vitest';
2
-
3
- import type { HexStringIsTrimmed, StringWithoutSuffix } from './strings';
4
-
5
- test('StringWithoutSuffix', () => {
6
- type A = StringWithoutSuffix<'hello', 'world'>;
7
- expectTypeOf<A>().toBeString();
8
-
9
- type B = StringWithoutSuffix<'hello', 'lo'>;
10
- expectTypeOf<B>().toBeNever();
11
-
12
- // Multiple suffixes test:
13
- type C = StringWithoutSuffix<'hello', 'lo' | 'world'>;
14
- expectTypeOf<C>().toBeNever();
15
-
16
- type D = StringWithoutSuffix<'hello world', 'lo' | 'world'>;
17
- expectTypeOf<D>().toBeNever();
18
-
19
- type E = StringWithoutSuffix<'hello world!', 'lo' | 'world'>;
20
- expectTypeOf<E>().toBeString();
21
- });
22
-
23
- test('HexStringIsTrimmed', () => {
24
- type A = HexStringIsTrimmed<'0x0'>;
25
- expectTypeOf<A>().toExtend<true>();
26
-
27
- type B = HexStringIsTrimmed<'0x00'>;
28
- expectTypeOf<B>().toExtend<false>();
29
-
30
- type C = HexStringIsTrimmed<'0x'>;
31
- expectTypeOf<C>().toExtend<false>();
32
- });
package/src/strings.ts DELETED
@@ -1,42 +0,0 @@
1
- import type { Branded } from './branded';
2
-
3
- /**
4
- * Guarantees that a string does not end with a suffix.
5
- * You can remove multiple suffixes by using a union.
6
- *
7
- * @example
8
- * type A = StringWithoutSuffix<'hello', 'world'>; // 'hello'
9
- * type B = StringWithoutSuffix<'hello', 'lo'>; // never
10
- * type C = StringWithoutSuffix<'hello world', 'lo' | 'world'>; // never
11
- */
12
- export type StringWithoutSuffix<
13
- T extends string,
14
- Suffix extends string,
15
- > = T extends `${infer _}${Suffix}` ? never : T;
16
-
17
- export type HexString = `0x${string}`;
18
-
19
- export declare const _NormalizedHexString: unique symbol;
20
-
21
- export type NormalizedHexString = Branded<typeof _NormalizedHexString, 'NormalizedHexString'>;
22
-
23
- /**
24
- * Guarantees that a hex string is trimmed.
25
- *
26
- * @example
27
- * type A = HexStringIsTrimmed<'0x0'>; // true
28
- * type B = HexStringIsTrimmed<'0x00'>; // false
29
- * type C = HexStringIsTrimmed<'0x'>; // false
30
- * type D = HexStringIsTrimmed<'0x100'>; // true
31
- */
32
- export type HexStringIsTrimmed<T extends HexString> = T extends '0x0'
33
- ? true
34
- : T extends '0x'
35
- ? false
36
- : T extends `0x0${string}`
37
- ? false
38
- : true;
39
-
40
- export declare const _NumberString: unique symbol;
41
-
42
- export type DecimalString = Branded<typeof _NumberString, 'DecimalString'>;
package/src/tuples.ts DELETED
@@ -1,65 +0,0 @@
1
- import type { BrandedError } from './branded';
2
-
3
- //check that the tuple T uses every type in the union K at least once
4
- export type IsComplete<
5
- T extends readonly (string | number | symbol)[],
6
- K extends string | number | symbol,
7
- > = Exclude<K, T[number]> extends never ? true : false;
8
-
9
- export type TryGetDuplicate<
10
- T extends readonly (string | number | symbol)[],
11
- Seen extends (string | number | symbol)[] = [],
12
- > = T extends [infer Head, ...infer Tail]
13
- ? Head extends Seen[number]
14
- ? Head
15
- : Head extends string | number | symbol
16
- ? Tail extends readonly (string | number | symbol)[]
17
- ? TryGetDuplicate<Tail, [...Seen, Head]>
18
- : false
19
- : false
20
- : false;
21
-
22
- //check that the tuple T is a valid ordering of AllKeys, using IsComplete and TryGetDuplicate
23
- //returns a branded error if there are missing keys or duplicates
24
- export type AssertUniqueCompleteSet<
25
- T extends readonly (string | number | symbol)[],
26
- AllKeys extends string | number | symbol,
27
- > =
28
- IsComplete<T, AllKeys> extends false
29
- ? BrandedError<`Missing key: ${Exclude<AllKeys extends Symbol ? 'ERR' : AllKeys, T[number]>}`>
30
- : TryGetDuplicate<T> extends false
31
- ? T
32
- : BrandedError<`Duplicate key found: ${TryGetDuplicate<T>}`>;
33
-
34
- type BuildTupleHelper<
35
- Element,
36
- Length extends number,
37
- Rest extends Element[],
38
- > = Rest['length'] extends Length
39
- ? readonly [...Rest] // Terminate with readonly array (aka tuple)
40
- : BuildTupleHelper<Element, Length, [Element, ...Rest]>;
41
-
42
- export type BuildTuple<Element, Length extends number> = number extends Length
43
- ? // Because `Length extends number` and `number extends Length`, then `Length` is not a specific finite number.
44
- readonly Element[] // It's not fixed length.
45
- : BuildTupleHelper<Element, Length, []>; // Otherwise it is a fixed length tuple.
46
-
47
- export type TuplesToObject<T extends readonly (readonly [PropertyKey, any])[]> = {
48
- [K in T[number] as K[0]]: K[1];
49
- };
50
-
51
- export type TuplePrefixUnion<T extends any[]> =
52
- | []
53
- | (Required<T> extends [...infer Init, any] ? Required<T> | TuplePrefixUnion<Init> : never);
54
-
55
- export type SubtractTuple<Minuend extends any[], Subtrahend extends any[]> = Subtrahend extends [
56
- any,
57
- ...infer S,
58
- ]
59
- ? Minuend extends [any, ...infer M]
60
- ? // keep subtracting
61
- SubtractTuple<M, S>
62
- : // subtrahend has a cardinality less than minuend
63
- never
64
- : // we fully subtracted already
65
- Minuend;
package/src/valueOf.ts DELETED
@@ -1,16 +0,0 @@
1
- export type IntersectionValueOf<T> = (
2
- T[keyof T] extends infer U ? (U extends any ? (x: U) => void : never) : never
3
- ) extends (x: infer I) => void
4
- ? I
5
- : never;
6
-
7
- /**
8
- * @description Creates a type that extracts the values of T.
9
- *
10
- * @example
11
- * ValueOf<{ a: string, b: number }>
12
- * => string | number
13
- *
14
- * @internal
15
- */
16
- export type ValueOf<T> = T[keyof T];
package/src/viem.ts DELETED
@@ -1,275 +0,0 @@
1
- /**
2
- * Filters out all members of {@link T} that are not {@link P}
3
- *
4
- * @param T - Items to filter
5
- * @param P - Type to filter out
6
- * @returns Filtered items
7
- *
8
- * @example
9
- * type Result = Filter<['a', 'b', 'c'], 'b'>
10
- * // ^? type Result = ['a', 'c']
11
- */
12
- export type Filter<
13
- T extends readonly unknown[],
14
- P,
15
- Acc extends readonly unknown[] = [],
16
- > = T extends readonly [infer F, ...infer Rest extends readonly unknown[]]
17
- ? [F] extends [P]
18
- ? Filter<Rest, P, [...Acc, F]>
19
- : Filter<Rest, P, Acc>
20
- : readonly [...Acc];
21
-
22
- /**
23
- * @description Checks if {@link T} can be narrowed further than {@link U}
24
- * @param T - Type to check
25
- * @param U - Type to compare against
26
- * @example
27
- * type Result = IsNarrowable<'foo', string>
28
- * // ^? true
29
- */
30
- export type IsNarrowable<T, U> =
31
- IsNever<(T extends U ? true : false) & (U extends T ? false : true)> extends true
32
- ? false
33
- : true;
34
-
35
- /**
36
- * @description Checks if {@link T} is `never`
37
- * @param T - Type to check
38
- * @example
39
- * type Result = IsNever<never>
40
- * // ^? type Result = true
41
- */
42
- export type IsNever<T> = [T] extends [never] ? true : false;
43
-
44
- /** Removes `readonly` from all properties of an object. */
45
- export type Mutable<type extends object> = {
46
- -readonly [key in keyof type]: type[key];
47
- };
48
-
49
- /**
50
- * @description Evaluates boolean "or" condition for {@link T} properties.
51
- * @param T - Type to check
52
- *
53
- * * @example
54
- * type Result = Or<[false, true, false]>
55
- * // ^? type Result = true
56
- *
57
- * @example
58
- * type Result = Or<[false, false, false]>
59
- * // ^? type Result = false
60
- */
61
- export type Or<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Tail]
62
- ? Head extends true
63
- ? true
64
- : Or<Tail>
65
- : false;
66
-
67
- /**
68
- * @description Checks if {@link T} is `undefined`
69
- * @param T - Type to check
70
- * @example
71
- * type Result = IsUndefined<undefined>
72
- * // ^? type Result = true
73
- */
74
- export type IsUndefined<T> = [undefined] extends [T] ? true : false;
75
-
76
- export type MaybePromise<T> = T | Promise<T>;
77
-
78
- /**
79
- * @description Makes attributes on the type T required if required is true.
80
- *
81
- * @example
82
- * MaybeRequired<{ a: string, b?: number }, true>
83
- * => { a: string, b: number }
84
- *
85
- * MaybeRequired<{ a: string, b?: number }, false>
86
- * => { a: string, b?: number }
87
- */
88
- export type MaybeRequired<T, required extends boolean> = required extends true
89
- ? ExactRequired<T>
90
- : T;
91
-
92
- /**
93
- * @description Assigns the properties of U onto T.
94
- *
95
- * @example
96
- * Assign<{ a: string, b: number }, { a: undefined, c: boolean }>
97
- * => { a: undefined, b: number, c: boolean }
98
- */
99
- export type Assign<T, U> = Assign_<T, U> & U;
100
- type Assign_<T, U> = {
101
- [K in keyof T as K extends keyof U ? (U[K] extends void ? never : K) : K]: K extends keyof U
102
- ? U[K]
103
- : T[K];
104
- };
105
-
106
- // TODO: Remove when peer dep `typescript@>=4.5` (NoInfer is native)
107
- export type NoInfer<type> = [type][type extends any ? 0 : never];
108
-
109
- /**
110
- * @description Constructs a type by excluding `undefined` from `T`.
111
- *
112
- * @example
113
- * NoUndefined<string | undefined>
114
- * => string
115
- *
116
- * @internal
117
- */
118
- export type NoUndefined<T> = T extends undefined ? never : T;
119
-
120
- /** Strict version of built-in Omit type */
121
- export type Omit<type, keys extends keyof type> = Pick<type, Exclude<keyof type, keys>>;
122
-
123
- /**
124
- * @description Creates a type that is a partial of T, but with the required keys K.
125
- *
126
- * @example
127
- * PartialBy<{ a: string, b: number }, 'a'>
128
- * => { a?: string, b: number }
129
- */
130
- export type PartialBy<T, K extends keyof T> = Omit<T, K> & ExactPartial<Pick<T, K>>;
131
-
132
- /**
133
- * @description Combines members of an intersection into a readable type.
134
- *
135
- * @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg}
136
- * @example
137
- * Prettify<{ a: string } & { b: string } & { c: number, d: bigint }>
138
- * => { a: string, b: string, c: number, d: bigint }
139
- */
140
- export type Prettify<T> = {
141
- [K in keyof T]: T[K];
142
- } & {};
143
-
144
- /** @internal */
145
- export type Evaluate<type> = {
146
- [key in keyof type]: type[key];
147
- } & {};
148
-
149
- /**
150
- * @description Creates a type that is T with the required keys K.
151
- *
152
- * @example
153
- * RequiredBy<{ a?: string, b: number }, 'a'>
154
- * => { a: string, b: number }
155
- */
156
- export type RequiredBy<T, K extends keyof T> = Omit<T, K> & ExactRequired<Pick<T, K>>;
157
-
158
- /**
159
- * @description Returns truthy if `array` contains `value`.
160
- *
161
- * @example
162
- * Some<[1, 2, 3], 2>
163
- * => true
164
- */
165
- export type Some<array extends readonly unknown[], value> = array extends readonly [
166
- value,
167
- ...unknown[],
168
- ]
169
- ? true
170
- : array extends readonly [unknown, ...infer rest]
171
- ? Some<rest, value>
172
- : false;
173
-
174
- export type UnionToTuple<
175
- union,
176
- ///
177
- last = LastInUnion<union>,
178
- > = [union] extends [never] ? [] : [...UnionToTuple<Exclude<union, last>>, last];
179
- type LastInUnion<U> =
180
- UnionToIntersection<U extends unknown ? (x: U) => 0 : never> extends (x: infer l) => 0
181
- ? l
182
- : never;
183
- type UnionToIntersection<union> = (union extends unknown ? (arg: union) => 0 : never) extends (
184
- arg: infer i,
185
- ) => 0
186
- ? i
187
- : never;
188
-
189
- export type IsUnion<
190
- union,
191
- ///
192
- union2 = union,
193
- > = union extends union2 ? ([union2] extends [union] ? false : true) : never;
194
-
195
- export type MaybePartial<type, enabled extends boolean | undefined> = enabled extends true
196
- ? Prettify<ExactPartial<type>>
197
- : type;
198
-
199
- export type ExactPartial<type> = {
200
- [key in keyof type]?: type[key] | undefined;
201
- };
202
-
203
- export type ExactRequired<type> = {
204
- [P in keyof type]-?: Exclude<type[P], undefined>;
205
- };
206
-
207
- export type OneOf<
208
- union extends object,
209
- fallback extends object | undefined = undefined,
210
- ///
211
- keys extends KeyofUnion<union> = KeyofUnion<union>,
212
- > = union extends infer item
213
- ? Prettify<
214
- item & {
215
- [key in Exclude<keys, keyof item>]?: fallback extends object
216
- ? key extends keyof fallback
217
- ? fallback[key]
218
- : undefined
219
- : undefined;
220
- }
221
- >
222
- : never;
223
- type KeyofUnion<type> = type extends type ? keyof type : never;
224
-
225
- ///////////////////////////////////////////////////////////////////////////
226
- // Loose types
227
-
228
- /**
229
- * Loose version of {@link Omit}
230
- * @internal
231
- */
232
- export type LooseOmit<type, keys extends string> = Pick<type, Exclude<keyof type, keys>>;
233
-
234
- ///////////////////////////////////////////////////////////////////////////
235
- // Union types
236
-
237
- export type UnionEvaluate<type> = type extends object ? Prettify<type> : type;
238
-
239
- export type UnionLooseOmit<type, keys extends string> = type extends any
240
- ? LooseOmit<type, keys>
241
- : never;
242
-
243
- /**
244
- * @description Construct a type with the properties of union type T except for those in type K.
245
- * @example
246
- * type Result = UnionOmit<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
247
- * => { b: number } | { b: undefined, c: number }
248
- */
249
- export type UnionOmit<type, keys extends keyof type> = type extends any ? Omit<type, keys> : never;
250
-
251
- /**
252
- * @description Construct a type with the properties of union type T except for those in type K.
253
- * @example
254
- * type Result = UnionOmit<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
255
- * => { b: number } | { b: undefined, c: number }
256
- */
257
- export type UnionPick<type, keys extends keyof type> = type extends any ? Pick<type, keys> : never;
258
-
259
- /**
260
- * @description Creates a type that is a partial of T, but with the required keys K.
261
- *
262
- * @example
263
- * PartialBy<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
264
- * => { a?: string, b: number } | { a?: string, b: undefined, c: number }
265
- */
266
- export type UnionPartialBy<T, K extends keyof T> = T extends any ? PartialBy<T, K> : never;
267
-
268
- /**
269
- * @description Creates a type that is T with the required keys K.
270
- *
271
- * @example
272
- * RequiredBy<{ a?: string, b: number } | { a?: string, c?: number }, 'a'>
273
- * => { a: string, b: number } | { a: string, c?: number }
274
- */
275
- export type UnionRequiredBy<T, K extends keyof T> = T extends any ? RequiredBy<T, K> : never;
@@ -1,5 +0,0 @@
1
- export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
2
-
3
- export type AllRequired<T> = {
4
- [K in keyof T]-?: T[K];
5
- };
@@ -1,54 +0,0 @@
1
- import { describe, expectTypeOf, it } from 'vitest';
2
-
3
- import type { DisallowedAny } from '../src/disallowedAny';
4
-
5
- describe('DisallowedAny type utility', () => {
6
- it('disallows bare any', () => {
7
- type R = DisallowedAny<any>;
8
- expectTypeOf<R>().toEqualTypeOf<never>();
9
- });
10
-
11
- it('passes through primitives', () => {
12
- expectTypeOf<DisallowedAny<string>>().toEqualTypeOf<string>();
13
- expectTypeOf<DisallowedAny<number>>().toEqualTypeOf<number>();
14
- expectTypeOf<DisallowedAny<boolean>>().toEqualTypeOf<boolean>();
15
- expectTypeOf<DisallowedAny<symbol>>().toEqualTypeOf<symbol>();
16
- expectTypeOf<DisallowedAny<bigint>>().toEqualTypeOf<bigint>();
17
- expectTypeOf<DisallowedAny<null>>().toEqualTypeOf<null>();
18
- expectTypeOf<DisallowedAny<undefined>>().toEqualTypeOf<undefined>();
19
- });
20
-
21
- it('does not treat unknown as any', () => {
22
- expectTypeOf<DisallowedAny<unknown>>().toEqualTypeOf<unknown>();
23
- });
24
-
25
- it('disallows unions that include any (any absorbs the union)', () => {
26
- type U1 = DisallowedAny<any | string>;
27
- expectTypeOf<U1>().toEqualTypeOf<never>();
28
-
29
- type U2 = DisallowedAny<string | number>;
30
- expectTypeOf<U2>().toEqualTypeOf<string | number>();
31
- });
32
-
33
- it('disallows intersections that include any (any absorbs the intersection)', () => {
34
- type I1 = DisallowedAny<any & { a: 1 }>;
35
- expectTypeOf<I1>().toEqualTypeOf<never>();
36
- });
37
-
38
- it('works with generics: when T is any it becomes never; otherwise it passes through', () => {
39
- type Wrap<T> = DisallowedAny<T>;
40
-
41
- type G1 = Wrap<any>;
42
- expectTypeOf<G1>().toEqualTypeOf<never>();
43
-
44
- type G2 = Wrap<{ x: string }>; // non-any generic
45
- expectTypeOf<G2>().toEqualTypeOf<{ x: string }>();
46
- });
47
-
48
- it('allows type constraints', () => {
49
- const myFunc = <T extends number>(_: DisallowedAny<T>): void => {};
50
- myFunc(5);
51
- //@ts-expect-error
52
- myFunc(5 as any);
53
- });
54
- });
@@ -1,27 +0,0 @@
1
- import { describe, expectTypeOf, it } from 'vitest';
2
-
3
- import type { Merge } from '../src/merge';
4
-
5
- describe('Merge type utility', () => {
6
- it('should handle empty object edge cases correctly', () => {
7
- // Test the main fix: empty objects should be handled properly
8
- type EmptyLeftMerge = Merge<{}, { a: string; b: number }>;
9
- expectTypeOf<EmptyLeftMerge>().toEqualTypeOf<{ a: string; b: number }>();
10
-
11
- type EmptyRightMerge = Merge<{ a: string; b: number }, {}>;
12
- expectTypeOf<EmptyRightMerge>().toEqualTypeOf<{ a: string; b: number }>();
13
-
14
- type BothEmptyMerge = Merge<{}, {}>;
15
- expectTypeOf<BothEmptyMerge>().toEqualTypeOf<{}>();
16
- });
17
-
18
- it('should merge types correctly for non-empty objects', () => {
19
- // Basic functionality should still work
20
- type BasicMerge = Merge<{ a: string }, { b: number }>;
21
- expectTypeOf<BasicMerge>().toEqualTypeOf<{ a: string; b: number }>();
22
-
23
- // Property override should work
24
- type OverrideMerge = Merge<{ a: string; b: string }, { b: number; c: boolean }>;
25
- expectTypeOf<OverrideMerge>().toEqualTypeOf<{ a: string; b: number; c: boolean }>();
26
- });
27
- });
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "@layerzerolabs/typescript-configuration/tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- "strictPropertyInitialization": false,
7
- "noUnusedLocals": false,
8
- "noUnusedParameters": false,
9
- "jsx": "react-jsx"
10
- },
11
- "exclude": [
12
- "node_modules",
13
- "**/__mocks__/*",
14
- "**/__tests__/*",
15
- "**/*.spec.ts",
16
- "**/*.test.ts",
17
- "dist"
18
- ],
19
- "include": ["src/**/*"]
20
- }
package/tsup.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- import { createPackageTsupConfig } from '@layerzerolabs/tsup-configuration';
4
-
5
- export default defineConfig(({ watch }) => ({
6
- ...createPackageTsupConfig(),
7
- clean: !watch,
8
- }));