66- [ Combinators] ( #combinators )
77 - [ The ` literal ` constructor] ( #the-literal-constructor )
88 - [ The ` nullable ` combinator] ( #the-nullable-combinator )
9- - [ The ` type ` combinator] ( #the-type -combinator )
9+ - [ The ` struct ` combinator] ( #the-struct -combinator )
1010 - [ The ` partial ` combinator] ( #the-partial-combinator )
1111 - [ The ` record ` combinator] ( #the-record-combinator )
1212 - [ The ` array ` combinator] ( #the-array-combinator )
@@ -100,12 +100,12 @@ The `nullable` combinator describes a nullable value
100100export const NullableString: D .Decoder <unknown , null | string > = D .nullable (D .string )
101101```
102102
103- ## The ` type ` combinator
103+ ## The ` struct ` combinator
104104
105- The ` type ` combinator describes an object with required fields.
105+ The ` struct ` combinator describes an object with required fields.
106106
107107``` ts
108- export const Person = D .type ({
108+ export const Person = D .struct ({
109109 name: D .string ,
110110 age: D .number
111111})
@@ -114,7 +114,7 @@ console.log(isRight(Person.decode({ name: 'name', age: 42 }))) // => true
114114console .log (isRight (Person .decode ({ name: ' name' }))) // => false
115115```
116116
117- The ` type ` combinator will strip additional fields while decoding
117+ The ` struct ` combinator will strip additional fields while decoding
118118
119119``` ts
120120console .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
184184
185185``` ts
186186export const Person = pipe (
187- D .type ({
187+ D .struct ({
188188 name: D .string
189189 }),
190190 D .intersect (
@@ -215,12 +215,12 @@ export const MySum: D.Decoder<
215215 }
216216 // v--- tag name
217217> = 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 })
224224})
225225```
226226
@@ -240,8 +240,8 @@ export const MySum: D.Decoder<
240240 b: number
241241 }
242242> = 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 })
245245})
246246```
247247
@@ -270,7 +270,7 @@ interface Category {
270270}
271271
272272const Category: D .Decoder <unknown , Category > = D .lazy (' Category' , () =>
273- D .type ({
273+ D .struct ({
274274 title: D .string ,
275275 subcategory: D .nullable (Category )
276276 })
@@ -291,14 +291,14 @@ interface Bar {
291291}
292292
293293const Foo: D .Decoder <unknown , Foo > = D .lazy (' Foo' , () =>
294- D .type ({
294+ D .struct ({
295295 foo: D .string ,
296296 bar: D .nullable (Bar )
297297 })
298298)
299299
300300const Bar: D .Decoder <unknown , Bar > = D .lazy (' Bar' , () =>
301- D .type ({
301+ D .struct ({
302302 bar: D .number ,
303303 foo: D .nullable (Foo )
304304 })
@@ -352,7 +352,7 @@ console.log(isRight(NumberFromString.decode('a'))) // => false
352352Static types can be extracted from decoders using the ` TypeOf ` and ` InputOf ` operators
353353
354354``` ts
355- export const Person = D .type ({
355+ export const Person = D .struct ({
356356 name: D .string ,
357357 age: D .number
358358})
@@ -382,7 +382,7 @@ export interface Person extends D.TypeOf<typeof Person> {}
382382``` ts
383383import { isLeft } from ' fp-ts/Either'
384384
385- export const Person = D .type ({
385+ export const Person = D .struct ({
386386 name: D .string ,
387387 age: D .number
388388})
0 commit comments