@layerzerolabs/typescript-utils 0.0.45 → 0.0.46

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.0.45",
3
+ "version": "0.0.46",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,8 +16,8 @@
16
16
  "devDependencies": {
17
17
  "tsup": "^8.4.0",
18
18
  "vitest": "^3.2.3",
19
- "@layerzerolabs/tsup-configuration": "0.0.45",
20
- "@layerzerolabs/typescript-configuration": "0.0.45"
19
+ "@layerzerolabs/tsup-configuration": "0.0.46",
20
+ "@layerzerolabs/typescript-configuration": "0.0.46"
21
21
  },
22
22
  "publishConfig": {
23
23
  "access": "restricted",
@@ -0,0 +1,33 @@
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 CHANGED
@@ -1,7 +1,20 @@
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
+
1
8
  export type DeepRequire<T> = {
2
9
  [P in keyof T]-?: DeepRequire<T[P]>;
3
10
  };
4
11
 
5
- export type DeepOptional<T> = {
6
- [P in keyof T]?: DeepOptional<T[P]>;
7
- };
12
+ export type DeepOptional<T> = T extends { [brandTag]: infer U }
13
+ ? Prettify<
14
+ { [brandTag]: U } & {
15
+ [P in keyof T]?: DeepOptional<T[P]>;
16
+ }
17
+ >
18
+ : {
19
+ [P in keyof T]?: DeepOptional<T[P]>;
20
+ };
package/src/strings.ts CHANGED
@@ -37,6 +37,6 @@ export type HexStringIsTrimmed<T extends HexString> = T extends '0x0'
37
37
  ? false
38
38
  : true;
39
39
 
40
- export declare const _DecimalString: unique symbol;
40
+ export declare const _NumberString: unique symbol;
41
41
 
42
- export type DecimalString = Branded<typeof _DecimalString, 'DecimalString'>;
42
+ export type DecimalString = Branded<typeof _NumberString, 'DecimalString'>;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/deep.ts"],"names":[],"mappings":";;;AAIA,cAAA,EAAA","file":"H4XPUNCM.js","sourcesContent":["export type DeepRequire<T> = {\n [P in keyof T]-?: DeepRequire<T[P]>;\n};\n\nexport type DeepOptional<T> = {\n [P in keyof T]?: DeepOptional<T[P]>;\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/deep.ts"],"names":["init_cjs_shims"],"mappings":";;;;;AAIAA,2BAAA,EAAA","file":"PUPSLF67.cjs","sourcesContent":["export type DeepRequire<T> = {\n [P in keyof T]-?: DeepRequire<T[P]>;\n};\n\nexport type DeepOptional<T> = {\n [P in keyof T]?: DeepOptional<T[P]>;\n};\n"]}