@mirohq/design-system-types 0.8.0 → 0.10.0
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/CHANGELOG.md +38 -0
- package/package.json +1 -1
- package/src/global.d.ts +66 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @mirohq-internal/design-system-types
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#617](https://github.com/miroapp-dev/design-system/pull/617) [`9ea14f4a`](https://github.com/miroapp-dev/design-system/commit/9ea14f4a48ab87d13c0a38e37186fb50ea642b02) Thanks [@ivanbanov](https://github.com/ivanbanov)! - Added two new types:
|
|
8
|
+
|
|
9
|
+
_OneOrMore_: creates a type that can be a single value or an array of that value.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
type Result = OneOrMore<number>
|
|
13
|
+
// number | number[]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
_MergeUnion_: merges two types by combining their properties. Overlapping properties result in a union of their values.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
type TypeA = { foo: number; bar: string }
|
|
20
|
+
type TypeB = { bar: boolean; baz: number }
|
|
21
|
+
|
|
22
|
+
type Result = MergeUnion<TypeA, TypeB>
|
|
23
|
+
// { foo: number, bar: string | boolean, baz: number }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 0.9.0
|
|
27
|
+
|
|
28
|
+
### Minor Changes
|
|
29
|
+
|
|
30
|
+
- [#611](https://github.com/miroapp-dev/design-system/pull/611) [`7ff8d5da`](https://github.com/miroapp-dev/design-system/commit/7ff8d5da5df65eeb28d1b6b3b0e6c12bacee97e1) Thanks [@ivanbanov](https://github.com/ivanbanov)! - Added new type MergeUnion.
|
|
31
|
+
|
|
32
|
+
Example
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
type TypeA = { foo: number; bar: string }
|
|
36
|
+
type TypeB = { bar: boolean; baz: number }
|
|
37
|
+
type Result = MergeUnion<TypeA, TypeB>
|
|
38
|
+
// { foo: number, bar: string | boolean, baz: number }
|
|
39
|
+
```
|
|
40
|
+
|
|
3
41
|
## 0.8.0
|
|
4
42
|
|
|
5
43
|
### Minor Changes
|
package/package.json
CHANGED
package/src/global.d.ts
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a type into a union of the value itself with null and undefined.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* type Text = string
|
|
6
|
+
* type Result = Nullable<Text>
|
|
7
|
+
*
|
|
8
|
+
* result: string | null | undefined
|
|
9
|
+
*/
|
|
1
10
|
export type Nullable<T> = T | null | undefined
|
|
2
11
|
|
|
12
|
+
/**
|
|
13
|
+
* A type that can be a number or a string representation of a number.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* type Num<X extends Numeric> = X
|
|
17
|
+
* type Result = Num<1 | '1'>
|
|
18
|
+
*/
|
|
3
19
|
export type Numeric = number | `${number}`
|
|
4
20
|
|
|
21
|
+
/**
|
|
22
|
+
* A type that can be a boolean or a string representation of a boolean.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* type Bool<X extends Booleanish> = X
|
|
26
|
+
* type Result = Bool<true | 'true'>
|
|
27
|
+
*/
|
|
5
28
|
export type Booleanish = boolean | `${boolean}`
|
|
6
29
|
|
|
7
30
|
/**
|
|
@@ -31,3 +54,46 @@ export type ExtractValidKeys<T> = T extends string | number | boolean | symbol
|
|
|
31
54
|
export type OmitFromUnion<T, K extends keyof any> = T extends any
|
|
32
55
|
? Omit<T, K>
|
|
33
56
|
: never
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Merges two types into a new type by combining their properties.
|
|
60
|
+
* If a property exists in both types, the resulting type will have the union of their values.
|
|
61
|
+
* If a property exists in only one type, the resulting type will have the value of that property.
|
|
62
|
+
* If a property exists in both types but has different types, the resulting type will have the union of their types.
|
|
63
|
+
* Any properties that exist in the second type but not in the first type will be included in the resulting type.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* Merge two types
|
|
67
|
+
*
|
|
68
|
+
* type TypeA = { foo: number, bar: string }
|
|
69
|
+
* type TypeB = { bar: boolean, baz: number }
|
|
70
|
+
*
|
|
71
|
+
* type Result = MergeUnion<TypeA, TypeB>
|
|
72
|
+
* { foo: number, bar: string | boolean, baz: number }
|
|
73
|
+
*/
|
|
74
|
+
export type MergeUnion<T, U> = {
|
|
75
|
+
[K in keyof T]: K extends keyof U ? U[K] | T[K] : T[K]
|
|
76
|
+
} & OmitFromUnion<U, keyof T>
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Convert a type into a union of the value itself and an array of the value.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* type Result = OneOrMore<number>
|
|
83
|
+
* number | number[]
|
|
84
|
+
*/
|
|
85
|
+
type OneOrMore<T> = T | T[]
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Converts a union type into an intersection type.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* type Union = { foo: number } | { bar: string }
|
|
92
|
+
* type Result = UnionToIntersection<Union>
|
|
93
|
+
* { foo: number } & { bar: string }
|
|
94
|
+
*/
|
|
95
|
+
type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (
|
|
96
|
+
x: infer I
|
|
97
|
+
) => any
|
|
98
|
+
? I
|
|
99
|
+
: never
|