@@ -148,3 +148,45 @@ const unionSchema = brandedUnion(
148
148
[Literal (' on' ), Literal (' off' )]
149
149
)
150
150
```
151
+
152
+ ### Fallback alternative
153
+
154
+ In case this library does not provide a specific schema factory for your type,
155
+ you can rely on ` brandedSchema ` . Notice that if you are using it for complex
156
+ schemas, it can loose some branding information from inner/nested properties.
157
+
158
+ ``` typescript
159
+ import type { FastBrand } from ' @coderspirit/nominal'
160
+ import {
161
+ brandedInteger ,
162
+ brandedSchema ,
163
+ brandedString ,
164
+ } from ' @coderspirit/nominal-typebox'
165
+ import { Record as TBRecord } from ' @sinclair/typebox'
166
+
167
+ const personNameSchema = brandedString <' PersonName' >()
168
+ const personAgeSchema = brandedInteger <' PersonAge' >()
169
+ const recordSchema = brandedSchema (' PeopleAges' , TBRecord (
170
+ personNameSchema ,
171
+ personAgeSchema ,
172
+ ))
173
+ const recordValidator = TypeCompiler .Compile (recordSchema )
174
+
175
+ const requestRecord = getRequestFromSomewhere () // unknown
176
+ if (! requestValidator .Check (requestRecord )) {
177
+ throw new Error (' Invalid request!' )
178
+ }
179
+
180
+ // OK
181
+ const recordSink: FastBrand <Record <string , number >, ' PeopleAges' > =
182
+ requestRecord
183
+
184
+ // @ts-expect-error Type Error!
185
+ const corruptedRecordSink: FastBrand <
186
+ Record <string , number >, ' PeopleAges'
187
+ > = { Alice: 20 , Bob: 30 }
188
+
189
+ // IMPORTANT!: Notice that `brandedSchema` is unable to preserve the
190
+ // brands of keys & values in the record. This limitation
191
+ // is due to the fact that `brandedSchema` is too generic.
192
+ ```
0 commit comments