6
6
- [ Combinators] ( #combinators )
7
7
- [ The ` literal ` constructor] ( #the-literal-constructor )
8
8
- [ The ` nullable ` combinator] ( #the-nullable-combinator )
9
- - [ The ` type ` combinator] ( #the-type -combinator )
9
+ - [ The ` struct ` combinator] ( #the-struct -combinator )
10
10
- [ The ` partial ` combinator] ( #the-partial-combinator )
11
11
- [ The ` record ` combinator] ( #the-record-combinator )
12
12
- [ The ` array ` combinator] ( #the-array-combinator )
@@ -100,12 +100,12 @@ The `nullable` combinator describes a nullable value
100
100
export const NullableString: D .Decoder <unknown , null | string > = D .nullable (D .string )
101
101
```
102
102
103
- ## The ` type ` combinator
103
+ ## The ` struct ` combinator
104
104
105
- The ` type ` combinator describes an object with required fields.
105
+ The ` struct ` combinator describes an object with required fields.
106
106
107
107
``` ts
108
- export const Person = D .type ({
108
+ export const Person = D .struct ({
109
109
name: D .string ,
110
110
age: D .number
111
111
})
@@ -114,7 +114,7 @@ console.log(isRight(Person.decode({ name: 'name', age: 42 }))) // => true
114
114
console .log (isRight (Person .decode ({ name: ' name' }))) // => false
115
115
```
116
116
117
- The ` type ` combinator will strip additional fields while decoding
117
+ The ` struct ` combinator will strip additional fields while decoding
118
118
119
119
``` ts
120
120
console .log (Person .decode ({ name: ' name' , age: 42 , rememberMe: true }))
@@ -184,7 +184,7 @@ The `intersect` combinator is useful in order to mix required and optional props
184
184
185
185
``` ts
186
186
export const Person = pipe (
187
- D .type ({
187
+ D .struct ({
188
188
name: D .string
189
189
}),
190
190
D .intersect (
@@ -215,12 +215,12 @@ export const MySum: D.Decoder<
215
215
}
216
216
// v--- tag name
217
217
> = D .sum (' type' )({
218
- // +----- all union members in the dictionary must own a field named like the chosen tag ("type" in this case)
219
- // |
220
- // v v----- this value must be equal to its corresponding dictionary key ("A" in this case)
221
- A: D .type ({ type: D .literal (' A' ), a: D .string }),
222
- // v----- this value must be equal to its corresponding dictionary key ("B" in this case)
223
- B: D .type ({ type: D .literal (' B' ), b: D .number })
218
+ // +----- all union members in the dictionary must own a field named like the chosen tag ("type" in this case)
219
+ // |
220
+ // v v----- this value must be equal to its corresponding dictionary key ("A" in this case)
221
+ A: D .struct ({ type: D .literal (' A' ), a: D .string }),
222
+ // v----- this value must be equal to its corresponding dictionary key ("B" in this case)
223
+ B: D .struct ({ type: D .literal (' B' ), b: D .number })
224
224
})
225
225
```
226
226
@@ -240,8 +240,8 @@ export const MySum: D.Decoder<
240
240
b: number
241
241
}
242
242
> = D .sum (' type' )({
243
- [1 ]: D .type ({ type: D .literal (1 ), a: D .string }),
244
- [2 ]: D .type ({ type: D .literal (2 ), b: D .number })
243
+ [1 ]: D .struct ({ type: D .literal (1 ), a: D .string }),
244
+ [2 ]: D .struct ({ type: D .literal (2 ), b: D .number })
245
245
})
246
246
```
247
247
@@ -270,7 +270,7 @@ interface Category {
270
270
}
271
271
272
272
const Category: D .Decoder <unknown , Category > = D .lazy (' Category' , () =>
273
- D .type ({
273
+ D .struct ({
274
274
title: D .string ,
275
275
subcategory: D .nullable (Category )
276
276
})
@@ -291,14 +291,14 @@ interface Bar {
291
291
}
292
292
293
293
const Foo: D .Decoder <unknown , Foo > = D .lazy (' Foo' , () =>
294
- D .type ({
294
+ D .struct ({
295
295
foo: D .string ,
296
296
bar: D .nullable (Bar )
297
297
})
298
298
)
299
299
300
300
const Bar: D .Decoder <unknown , Bar > = D .lazy (' Bar' , () =>
301
- D .type ({
301
+ D .struct ({
302
302
bar: D .number ,
303
303
foo: D .nullable (Foo )
304
304
})
@@ -352,7 +352,7 @@ console.log(isRight(NumberFromString.decode('a'))) // => false
352
352
Static types can be extracted from decoders using the ` TypeOf ` and ` InputOf ` operators
353
353
354
354
``` ts
355
- export const Person = D .type ({
355
+ export const Person = D .struct ({
356
356
name: D .string ,
357
357
age: D .number
358
358
})
@@ -382,7 +382,7 @@ export interface Person extends D.TypeOf<typeof Person> {}
382
382
``` ts
383
383
import { isLeft } from ' fp-ts/Either'
384
384
385
- export const Person = D .type ({
385
+ export const Person = D .struct ({
386
386
name: D .string ,
387
387
age: D .number
388
388
})
0 commit comments