@strictly/define 0.0.1

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.
Files changed (162) hide show
  1. package/.eslintrc.cjs +31 -0
  2. package/.out/index.d.ts +20 -0
  3. package/.out/index.js +20 -0
  4. package/.out/transformers/copies/copy.d.ts +4 -0
  5. package/.out/transformers/copies/copy.js +7 -0
  6. package/.out/transformers/copies/copy_to.d.ts +6 -0
  7. package/.out/transformers/copies/copy_to.js +91 -0
  8. package/.out/transformers/copies/mobx_copy.d.ts +5 -0
  9. package/.out/transformers/copies/mobx_copy.js +42 -0
  10. package/.out/transformers/copies/specs/copy_to.tests.d.ts +1 -0
  11. package/.out/transformers/copies/specs/copy_to.tests.js +97 -0
  12. package/.out/transformers/copies/specs/mobx_copy.tests.d.ts +1 -0
  13. package/.out/transformers/copies/specs/mobx_copy.tests.js +19 -0
  14. package/.out/transformers/flatteners/flatten_accessors_of.d.ts +5 -0
  15. package/.out/transformers/flatteners/flatten_accessors_of.js +11 -0
  16. package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.d.ts +3 -0
  17. package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.js +10 -0
  18. package/.out/transformers/flatteners/flatten_type_def_to.d.ts +4 -0
  19. package/.out/transformers/flatteners/flatten_type_def_to.js +49 -0
  20. package/.out/transformers/flatteners/flatten_type_defs_of.d.ts +3 -0
  21. package/.out/transformers/flatteners/flatten_type_defs_of.js +7 -0
  22. package/.out/transformers/flatteners/flatten_value_type_to.d.ts +11 -0
  23. package/.out/transformers/flatteners/flatten_value_type_to.js +79 -0
  24. package/.out/transformers/flatteners/flatten_value_types_of.d.ts +3 -0
  25. package/.out/transformers/flatteners/flatten_value_types_of.js +7 -0
  26. package/.out/transformers/flatteners/json_path.d.ts +2 -0
  27. package/.out/transformers/flatteners/json_path.js +14 -0
  28. package/.out/transformers/flatteners/specs/flatten_accessors_of.tests.d.ts +1 -0
  29. package/.out/transformers/flatteners/specs/flatten_accessors_of.tests.js +90 -0
  30. package/.out/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.d.ts +1 -0
  31. package/.out/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.js +94 -0
  32. package/.out/transformers/flatteners/specs/flatten_type_def_to.tests.d.ts +1 -0
  33. package/.out/transformers/flatteners/specs/flatten_type_def_to.tests.js +110 -0
  34. package/.out/transformers/flatteners/specs/flatten_type_defs_of.tests.d.ts +1 -0
  35. package/.out/transformers/flatteners/specs/flatten_type_defs_of.tests.js +17 -0
  36. package/.out/transformers/flatteners/specs/flatten_value_type_to.tests.d.ts +1 -0
  37. package/.out/transformers/flatteners/specs/flatten_value_type_to.tests.js +297 -0
  38. package/.out/transformers/flatteners/specs/flatten_value_types_of.tests.d.ts +1 -0
  39. package/.out/transformers/flatteners/specs/flatten_value_types_of.tests.js +37 -0
  40. package/.out/transformers/flatteners/specs/value_path_to_type_path.tests.d.ts +1 -0
  41. package/.out/transformers/flatteners/specs/value_path_to_type_path.tests.js +167 -0
  42. package/.out/transformers/flatteners/value_path_to_type_path.d.ts +2 -0
  43. package/.out/transformers/flatteners/value_path_to_type_path.js +96 -0
  44. package/.out/tsconfig.json +15 -0
  45. package/.out/tsconfig.tsbuildinfo +1 -0
  46. package/.out/tsup.config.d.ts +3 -0
  47. package/.out/tsup.config.js +12 -0
  48. package/.out/types/builders.d.ts +62 -0
  49. package/.out/types/builders.js +148 -0
  50. package/.out/types/definitions.d.ts +41 -0
  51. package/.out/types/definitions.js +26 -0
  52. package/.out/types/flattened.d.ts +2 -0
  53. package/.out/types/flattened.js +1 -0
  54. package/.out/types/flattened_accessors_of.d.ts +9 -0
  55. package/.out/types/flattened_accessors_of.js +1 -0
  56. package/.out/types/flattened_type_defs_of.d.ts +21 -0
  57. package/.out/types/flattened_type_defs_of.js +1 -0
  58. package/.out/types/flattened_value_types_of.d.ts +6 -0
  59. package/.out/types/flattened_value_types_of.js +1 -0
  60. package/.out/types/json_path_of.d.ts +1 -0
  61. package/.out/types/json_path_of.js +1 -0
  62. package/.out/types/json_paths_of.d.ts +16 -0
  63. package/.out/types/json_paths_of.js +1 -0
  64. package/.out/types/mobx_value_type_of.d.ts +11 -0
  65. package/.out/types/mobx_value_type_of.js +2 -0
  66. package/.out/types/partial_type_def_of.d.ts +40 -0
  67. package/.out/types/partial_type_def_of.js +1 -0
  68. package/.out/types/readonly_type_def_of.d.ts +29 -0
  69. package/.out/types/readonly_type_def_of.js +1 -0
  70. package/.out/types/specs/builder.tests.d.ts +1 -0
  71. package/.out/types/specs/builder.tests.js +93 -0
  72. package/.out/types/specs/flattened_accessors_of.tests.d.ts +1 -0
  73. package/.out/types/specs/flattened_accessors_of.tests.js +11 -0
  74. package/.out/types/specs/flattened_type_defs_of.tests.d.ts +1 -0
  75. package/.out/types/specs/flattened_type_defs_of.tests.js +71 -0
  76. package/.out/types/specs/flattened_value_types_of.tests.d.ts +1 -0
  77. package/.out/types/specs/flattened_value_types_of.tests.js +11 -0
  78. package/.out/types/specs/json_paths_of.tests.d.ts +1 -0
  79. package/.out/types/specs/json_paths_of.tests.js +199 -0
  80. package/.out/types/specs/partial_type_def_of.tests.d.ts +1 -0
  81. package/.out/types/specs/partial_type_def_of.tests.js +50 -0
  82. package/.out/types/specs/readonly_type_def_of.tests.d.ts +1 -0
  83. package/.out/types/specs/readonly_type_def_of.tests.js +55 -0
  84. package/.out/types/specs/strict_definitions.tests.d.ts +1 -0
  85. package/.out/types/specs/strict_definitions.tests.js +42 -0
  86. package/.out/types/specs/value_to_type_paths_of.tests.d.ts +1 -0
  87. package/.out/types/specs/value_to_type_paths_of.tests.js +90 -0
  88. package/.out/types/specs/value_type_of.tests.d.ts +1 -0
  89. package/.out/types/specs/value_type_of.tests.js +91 -0
  90. package/.out/types/specs/value_types_of_discriminated_union.tests.d.ts +1 -0
  91. package/.out/types/specs/value_types_of_discriminated_union.tests.js +9 -0
  92. package/.out/types/strict_definitions.d.ts +44 -0
  93. package/.out/types/strict_definitions.js +1 -0
  94. package/.out/types/value_to_type_paths_of.d.ts +22 -0
  95. package/.out/types/value_to_type_paths_of.js +1 -0
  96. package/.out/types/value_type_of.d.ts +24 -0
  97. package/.out/types/value_type_of.js +1 -0
  98. package/.out/types/value_types_of_discriminated_union.d.ts +9 -0
  99. package/.out/types/value_types_of_discriminated_union.js +1 -0
  100. package/.out/vitest.workspace.d.ts +2 -0
  101. package/.out/vitest.workspace.js +7 -0
  102. package/.turbo/turbo-build.log +18 -0
  103. package/.turbo/turbo-check-types.log +3 -0
  104. package/.turbo/turbo-release$colon$exports.log +3 -0
  105. package/README.md +12 -0
  106. package/dist/index.cjs +798 -0
  107. package/dist/index.d.cts +301 -0
  108. package/dist/index.d.ts +301 -0
  109. package/dist/index.js +775 -0
  110. package/index.ts +20 -0
  111. package/package.exports.json +18 -0
  112. package/package.json +45 -0
  113. package/transformers/copies/copy.ts +18 -0
  114. package/transformers/copies/copy_to.ts +226 -0
  115. package/transformers/copies/mobx_copy.ts +81 -0
  116. package/transformers/copies/specs/copy_to.tests.ts +143 -0
  117. package/transformers/copies/specs/mobx_copy.tests.ts +26 -0
  118. package/transformers/flatteners/flatten_accessors_of.ts +43 -0
  119. package/transformers/flatteners/flatten_json_value_to_type_paths_of.ts +39 -0
  120. package/transformers/flatteners/flatten_type_def_to.ts +127 -0
  121. package/transformers/flatteners/flatten_type_defs_of.ts +16 -0
  122. package/transformers/flatteners/flatten_value_type_to.ts +227 -0
  123. package/transformers/flatteners/flatten_value_types_of.ts +23 -0
  124. package/transformers/flatteners/json_path.ts +15 -0
  125. package/transformers/flatteners/specs/flatten_accessors_of.tests.ts +113 -0
  126. package/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.ts +115 -0
  127. package/transformers/flatteners/specs/flatten_type_def_to.tests.ts +146 -0
  128. package/transformers/flatteners/specs/flatten_type_defs_of.tests.ts +26 -0
  129. package/transformers/flatteners/specs/flatten_value_type_to.tests.ts +452 -0
  130. package/transformers/flatteners/specs/flatten_value_types_of.tests.ts +46 -0
  131. package/transformers/flatteners/specs/value_path_to_type_path.tests.ts +240 -0
  132. package/transformers/flatteners/value_path_to_type_path.ts +164 -0
  133. package/tsconfig.build.json +11 -0
  134. package/tsconfig.json +15 -0
  135. package/tsup.config.ts +16 -0
  136. package/types/builders.ts +284 -0
  137. package/types/definitions.ts +106 -0
  138. package/types/flattened.ts +5 -0
  139. package/types/flattened_accessors_of.ts +15 -0
  140. package/types/flattened_type_defs_of.ts +130 -0
  141. package/types/flattened_value_types_of.ts +11 -0
  142. package/types/json_path_of.ts +7 -0
  143. package/types/json_paths_of.ts +129 -0
  144. package/types/mobx_value_type_of.ts +16 -0
  145. package/types/partial_type_def_of.ts +64 -0
  146. package/types/readonly_type_def_of.ts +53 -0
  147. package/types/specs/builder.tests.ts +295 -0
  148. package/types/specs/flattened_accessors_of.tests.ts +27 -0
  149. package/types/specs/flattened_type_defs_of.tests.ts +212 -0
  150. package/types/specs/flattened_value_types_of.tests.ts +21 -0
  151. package/types/specs/json_paths_of.tests.ts +304 -0
  152. package/types/specs/partial_type_def_of.tests.ts +251 -0
  153. package/types/specs/readonly_type_def_of.tests.ts +158 -0
  154. package/types/specs/strict_definitions.tests.ts +184 -0
  155. package/types/specs/value_to_type_paths_of.tests.ts +181 -0
  156. package/types/specs/value_type_of.tests.ts +329 -0
  157. package/types/specs/value_types_of_discriminated_union.tests.ts +30 -0
  158. package/types/strict_definitions.ts +107 -0
  159. package/types/value_to_type_paths_of.ts +184 -0
  160. package/types/value_type_of.ts +84 -0
  161. package/types/value_types_of_discriminated_union.ts +14 -0
  162. package/vitest.workspace.ts +11 -0
@@ -0,0 +1,30 @@
1
+ import { type SimplifyDeep } from 'type-fest'
2
+ import {
3
+ booleanType,
4
+ numberType,
5
+ object,
6
+ union,
7
+ } from 'types/builders'
8
+ import { type ValueTypesOfDiscriminatedUnion } from 'types/value_types_of_discriminated_union'
9
+
10
+ describe('ValueTypesOfDiscriminatedUnion', function () {
11
+ it('matches expected type', function () {
12
+ const { definition } = union('d')
13
+ .add('a', object().set('x', numberType))
14
+ .add('b', object().set('y', booleanType))
15
+ type T = SimplifyDeep<ValueTypesOfDiscriminatedUnion<
16
+ typeof definition
17
+ >>
18
+
19
+ expectTypeOf<T>().toEqualTypeOf<{
20
+ readonly a: {
21
+ d: 'a',
22
+ x: number,
23
+ },
24
+ readonly b: {
25
+ d: 'b',
26
+ y: boolean,
27
+ },
28
+ }>()
29
+ })
30
+ })
@@ -0,0 +1,107 @@
1
+ import {
2
+ type IsEqual,
3
+ type Simplify,
4
+ } from 'type-fest'
5
+ import {
6
+ type ObjectFieldKey,
7
+ type RecordKeyType,
8
+ type TypeDefType,
9
+ type UnionKey,
10
+ } from './definitions'
11
+
12
+ // TODO rename to something more descriptive (e.g. introspectable definitions, deterministic
13
+ // definitions, discriminated definitions). Maybe should just replace definitions since most
14
+ // of the supporting types and utilities don't support non-strict definitions anyway
15
+
16
+ // strict equivalent of type defs, basically just makes it so Union is introspectable
17
+
18
+ export type StrictType<T extends StrictTypeDef = StrictTypeDef> = {
19
+ readonly definition: T,
20
+ }
21
+
22
+ export type StrictTypeDef =
23
+ | StrictLiteralTypeDef
24
+ | StrictListTypeDef
25
+ | StrictRecordTypeDef
26
+ | StrictObjectTypeDef
27
+ | StrictUnionTypeDef
28
+
29
+ // used to avoid TS complaining about circular references
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ type AnyTypeDef = any
32
+
33
+ // literal
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ export type StrictLiteralTypeDef<V = any> = {
36
+ readonly type: TypeDefType.Literal,
37
+ readonly valuePrototype: [V],
38
+ }
39
+
40
+ // list
41
+ export type StrictListTypeDef<
42
+ E extends StrictTypeDef = AnyTypeDef,
43
+ > = {
44
+ readonly type: TypeDefType.List,
45
+ // readonly is inherited by the output
46
+ readonly elements: E,
47
+ }
48
+
49
+ // map
50
+ export type StrictRecordTypeDef<
51
+ K extends RecordKeyType = RecordKeyType,
52
+ // if `V` includes `undefined` the map is partial
53
+ V extends StrictTypeDef | undefined = AnyTypeDef,
54
+ > = {
55
+ readonly type: TypeDefType.Record,
56
+ // never actually populate
57
+ readonly keyPrototype: K,
58
+ // readonly is inherited by the output
59
+ readonly valueTypeDef: V,
60
+ }
61
+
62
+ // structured type
63
+
64
+ // NOTE we use the `readonly` and `?` (partial) status of these field definitions
65
+ // to describe the same attributes of the fields
66
+ export type StrictStructuredTypeDefFields = {
67
+ [Key: ObjectFieldKey]: AnyTypeDef,
68
+ }
69
+
70
+ // NOTE: we cannot collapse this type to
71
+ // `StructuredTypeDef = StructuredTypeDefFields`
72
+ // as we rely on the `fields` field being unique to discriminate between different
73
+ // TypeDefs
74
+ export type StrictObjectTypeDef<
75
+ Fields extends StrictStructuredTypeDefFields = StrictStructuredTypeDefFields,
76
+ > = {
77
+ readonly type: TypeDefType.Object,
78
+ readonly fields: Fields,
79
+ }
80
+
81
+ export type StrictUnionTypeDef<
82
+ D extends string | null = string | null,
83
+ U extends Readonly<Record<UnionKey, AnyTypeDef>> = Readonly<Record<UnionKey, AnyTypeDef>>,
84
+ > = D extends null ? IsStrictUnion<U> extends true ? {
85
+ readonly discriminator: null,
86
+ readonly type: TypeDefType.Union,
87
+ readonly unions: U,
88
+ }
89
+ : never
90
+ // TODO enforce the unions are all structs
91
+ : {
92
+ readonly discriminator: D,
93
+ readonly type: TypeDefType.Union,
94
+ readonly unions: U,
95
+ }
96
+
97
+ // tests whether the union is composed of one non-constant value (at ['0']) and the rest
98
+ // constants
99
+ export type IsStrictUnion<U extends Readonly<Record<UnionKey, AnyTypeDef>>> = IsEqual<
100
+ U,
101
+ Simplify<{
102
+ readonly [K in keyof Omit<U, '0'> as U[K] extends StrictLiteralTypeDef ? K : never]: U[K]
103
+ } & (U extends { readonly ['0']: AnyTypeDef } ? {
104
+ readonly ['0']: U['0'],
105
+ }
106
+ : {})>
107
+ >
@@ -0,0 +1,184 @@
1
+ import {
2
+ type SimplifyDeep,
3
+ type UnionToIntersection,
4
+ } from 'type-fest'
5
+ import {
6
+ type ListTypeDef,
7
+ type LiteralTypeDef,
8
+ type ObjectTypeDef,
9
+ type RecordTypeDef,
10
+ type TypeDef,
11
+ type UnionTypeDef,
12
+ } from './definitions'
13
+ import {
14
+ type Depths,
15
+ type StartingDepth,
16
+ } from './flattened'
17
+ import { type JsonPathOf } from './json_path_of'
18
+ import { type StrictType } from './strict_definitions'
19
+
20
+ export type ValueToTypePathsOf<
21
+ T extends StrictType,
22
+ SegmentOverride extends string = '*',
23
+ Path extends string = '$',
24
+ > = SimplifyDeep<InternalFlattenedJsonPathsOf<
25
+ T['definition'],
26
+ SegmentOverride,
27
+ Path,
28
+ Path,
29
+ StartingDepth
30
+ >>
31
+
32
+ type InternalFlattenedJsonPathsOf<
33
+ T extends TypeDef,
34
+ SegmentOverride extends string,
35
+ ValuePath extends string,
36
+ TypePath extends string,
37
+ Depth extends number,
38
+ > =
39
+ & {
40
+ readonly [K in ValuePath]: TypePath
41
+ }
42
+ & InternalFlattenedJsonPathsOfChildren<T, SegmentOverride, ValuePath, TypePath, '', Depth>
43
+
44
+ type InternalFlattenedJsonPathsOfChildren<
45
+ T extends TypeDef,
46
+ SegmentOverride extends string,
47
+ ValuePath extends string,
48
+ TypePath extends string,
49
+ Qualifier extends string,
50
+ Depth extends number,
51
+ NextDepth extends number = Depths[Depth],
52
+ > = NextDepth extends -1 ? never
53
+ : T extends LiteralTypeDef ? InternalFlattenedJsonPathsOfLiteralChildren
54
+ : T extends ListTypeDef ? InternalFlattenedJsonPathsOfListChildren<
55
+ T,
56
+ SegmentOverride,
57
+ ValuePath,
58
+ TypePath,
59
+ NextDepth
60
+ >
61
+ : T extends RecordTypeDef ? InternalFlattenedJsonPathsOfRecordChildren<
62
+ T,
63
+ SegmentOverride,
64
+ ValuePath,
65
+ TypePath,
66
+ NextDepth
67
+ >
68
+ : T extends ObjectTypeDef ? InternalFlattenedJsonPathsOfObjectChildren<
69
+ T,
70
+ SegmentOverride,
71
+ ValuePath,
72
+ TypePath,
73
+ Qualifier,
74
+ NextDepth
75
+ >
76
+ : T extends UnionTypeDef ? InternalFlattenedJsonPathsOfUnionChildren<
77
+ T,
78
+ SegmentOverride,
79
+ ValuePath,
80
+ TypePath,
81
+ Qualifier,
82
+ NextDepth
83
+ >
84
+ : never
85
+
86
+ type InternalFlattenedJsonPathsOfLiteralChildren = {}
87
+
88
+ type InternalFlattenedJsonPathsOfListChildren<
89
+ T extends ListTypeDef,
90
+ SegmentOverride extends string,
91
+ ValuePath extends string,
92
+ TypePath extends string,
93
+ Depth extends number,
94
+ > = InternalFlattenedJsonPathsOf<
95
+ T['elements'],
96
+ SegmentOverride,
97
+ JsonPathOf<ValuePath, number>,
98
+ JsonPathOf<TypePath, number, SegmentOverride>,
99
+ Depth
100
+ >
101
+
102
+ type InternalFlattenedJsonPathsOfRecordChildren<
103
+ T extends RecordTypeDef,
104
+ SegmentOverride extends string,
105
+ ValuePath extends string,
106
+ TypePath extends string,
107
+ Depth extends number,
108
+ > = InternalFlattenedJsonPathsOf<
109
+ T['valueTypeDef'],
110
+ SegmentOverride,
111
+ JsonPathOf<ValuePath, T['keyPrototype']>,
112
+ JsonPathOf<TypePath, T['keyPrototype'], SegmentOverride>,
113
+ Depth
114
+ >
115
+
116
+ type InternalFlattenedJsonPathsOfObjectChildren<
117
+ T extends ObjectTypeDef,
118
+ SegmentOverride extends string,
119
+ ValuePath extends string,
120
+ TypePath extends string,
121
+ Qualifier extends string,
122
+ Depth extends number,
123
+ > = T extends ObjectTypeDef<infer Fields> ? keyof Fields extends string ? UnionToIntersection<
124
+ {
125
+ readonly [K in keyof Fields]-?: InternalFlattenedJsonPathsOf<
126
+ Exclude<Fields[K], undefined>,
127
+ SegmentOverride,
128
+ JsonPathOf<ValuePath, `${Qualifier}${K}`>,
129
+ JsonPathOf<TypePath, `${Qualifier}${K}`>,
130
+ Depth
131
+ >
132
+ }[keyof Fields]
133
+ >
134
+ : never
135
+ : never
136
+
137
+ // type InternalFlattenedJsonPathsOfUnionChildren<
138
+ // T extends UnionTypeDef,
139
+ // SegmentOverride extends string,
140
+ // ValuePath extends string,
141
+ // TypePath extends string,
142
+ // Depth extends number,
143
+ // > = T extends UnionTypeDef<infer D, infer Unions> ?
144
+ // & ({
145
+ // [K in keyof Unions]: InternalFlattenedJsonPathsOfChildren<
146
+ // Unions[K],
147
+ // SegmentOverride,
148
+ // ValuePath,
149
+ // TypePath,
150
+ // Depth
151
+ // >
152
+ // }[keyof Unions])
153
+ // & (D extends string ? ReadonlyRecord<JsonPathOf<ValuePath, D>, JsonPathOf<TypePath, D>> : {})
154
+ // : never
155
+
156
+ type InternalFlattenedJsonPathsOfUnionChildren<
157
+ T extends UnionTypeDef,
158
+ SegmentOverride extends string,
159
+ ValuePath extends string,
160
+ TypePath extends string,
161
+ Qualifier extends string,
162
+ Depth extends number,
163
+ > = T extends UnionTypeDef<infer D, infer Unions> ? keyof Unions extends string ? D extends null ? UnionToIntersection<{
164
+ readonly [K in keyof Unions]: InternalFlattenedJsonPathsOfChildren<
165
+ Unions[K],
166
+ SegmentOverride,
167
+ ValuePath,
168
+ TypePath,
169
+ '',
170
+ Depth
171
+ >
172
+ }[keyof Unions]>
173
+ : UnionToIntersection<{
174
+ readonly [K in keyof Unions]: InternalFlattenedJsonPathsOfChildren<
175
+ Unions[K],
176
+ SegmentOverride,
177
+ ValuePath,
178
+ TypePath,
179
+ `${Qualifier}${K}:`,
180
+ Depth
181
+ >
182
+ }[keyof Unions]>
183
+ : never
184
+ : never
@@ -0,0 +1,84 @@
1
+ import {
2
+ type IsFieldReadonly,
3
+ } from '@strictly/base'
4
+ import {
5
+ type ListTypeDef,
6
+ type LiteralTypeDef,
7
+ type ObjectTypeDef,
8
+ type RecordTypeDef,
9
+ type Type,
10
+ type TypeDef,
11
+ type UnionTypeDef,
12
+ } from './definitions'
13
+
14
+ export type ValueTypeOf<
15
+ T,
16
+ Extra = {},
17
+ > = T extends Type ? InternalValueTypeOf<T['definition'], Extra> : never
18
+
19
+ export type InternalValueTypeOf<
20
+ F extends TypeDef,
21
+ Extra,
22
+ > = F extends LiteralTypeDef ? InternalValueTypeOfLiteral<F>
23
+ : F extends ListTypeDef ? InternalValueTypeOfList<F, Extra>
24
+ : F extends RecordTypeDef ? InternalValueTypeOfRecord<F, Extra>
25
+ : F extends ObjectTypeDef ? InternalValueTypeOfObject<F, Extra>
26
+ : F extends UnionTypeDef ? InternalValueTypeOfUnion<F, Extra>
27
+ : never
28
+
29
+ type InternalValueTypeOfLiteral<F extends LiteralTypeDef> = F['valuePrototype'][number]
30
+
31
+ type InternalValueTypeOfList<F extends ListTypeDef, Extra> = IsFieldReadonly<F, 'elements'> extends true
32
+ ? readonly InternalValueTypeOf<
33
+ F['elements'],
34
+ Extra
35
+ >[] & Extra
36
+ : InternalValueTypeOf<
37
+ F['elements'],
38
+ Extra
39
+ >[] & Extra
40
+
41
+ type InternalValueTypeOfRecord<
42
+ F extends RecordTypeDef,
43
+ Extra,
44
+ > = undefined extends F['valueTypeDef']
45
+ // partial
46
+ ? IsFieldReadonly<F, 'valueTypeDef'> extends true
47
+ // readonly
48
+ ? {
49
+ readonly [k in F['keyPrototype']]?: InternalValueTypeOf<F['valueTypeDef'], Extra>
50
+ }
51
+ : {
52
+ [k in F['keyPrototype']]?: InternalValueTypeOf<F['valueTypeDef'], Extra>
53
+ }
54
+ // complete
55
+ : IsFieldReadonly<F, 'valueTypeDef'> extends true
56
+ // readonly
57
+ ? {
58
+ readonly [k in F['keyPrototype']]: InternalValueTypeOf<F['valueTypeDef'], Extra>
59
+ }
60
+ : {
61
+ [k in F['keyPrototype']]: InternalValueTypeOf<F['valueTypeDef'], Extra>
62
+ }
63
+
64
+ type InternalValueTypeOfObject<
65
+ F extends ObjectTypeDef,
66
+ Extra,
67
+ > = F extends ObjectTypeDef<infer Fields> ? {
68
+ [K in keyof Fields]: InternalValueTypeOf<
69
+ Fields[K],
70
+ Extra
71
+ >
72
+ } & Extra
73
+ : never
74
+
75
+ type InternalValueTypeOfUnion<
76
+ F extends UnionTypeDef,
77
+ Extra,
78
+ > = F extends UnionTypeDef<infer D, infer U> ? D extends string ? {
79
+ [K in keyof U]: InternalValueTypeOf<U[K], Extra> & Readonly<Record<D, K>>
80
+ }[keyof U]
81
+ : {
82
+ [K in keyof U]: InternalValueTypeOf<U[K], Extra>
83
+ }[keyof U]
84
+ : never
@@ -0,0 +1,14 @@
1
+ import { type UnionTypeDef } from './definitions'
2
+ import { type ValueTypeOf } from './value_type_of'
3
+
4
+ // gets a record of the values types for a discriminated union mapped according to
5
+ // their discriminators
6
+ export type ValueTypesOfDiscriminatedUnion<
7
+ U extends UnionTypeDef,
8
+ > = U extends UnionTypeDef<infer D, infer Unions> ? D extends string ? {
9
+ [K in keyof Unions]: ValueTypeOf<{ definition: Unions[K] }> & {
10
+ [KD in D]: K
11
+ }
12
+ }
13
+ : never
14
+ : never
@@ -0,0 +1,11 @@
1
+ import { createVitestUserConfig } from '@strictly/support-vite'
2
+ import {
3
+ defineWorkspace,
4
+ } from 'vitest/config'
5
+
6
+ import tsconfig from './tsconfig.json'
7
+
8
+ export default defineWorkspace([
9
+ '.',
10
+ createVitestUserConfig(tsconfig),
11
+ ] as const)