diff --git a/README.md b/README.md index c10e2f09d..1f938b807 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ export const string: t.Type = { } ``` -Note: The `_A` field contains a dummy value and is useful to extract a static type from the runtime type (see the section "TypeScript integration" below) +Note: The `_A` field contains a dummy value and is useful to extract a static type from the runtime type (see the ["TypeScript integration"](#typescript-integration) section below) A runtime type can be used to validate an object in memory (for example an API payload) @@ -107,6 +107,8 @@ type IPerson = { } ``` +## Recursive types + Note that recursive types can't be inferred ```js @@ -140,23 +142,23 @@ import * as t from 'io-ts' | any | `any` | `t.any` | | never | `never` | `t.never` | | integer | ✘ | `t.Integer` | -| generic array | `Array` | `t.Array` | -| generic dictionary | `{ [key: string]: any }` | `t.Dictionary` | +| array of any | `Array` | `t.Array` | +| array of type | `Array` | `t.array(A)` | +| dictionary of any | `{ [key: string]: any }` | `t.Dictionary` | +| dictionary of type | `{ [key: A]: B }` | `t.dictionary(A, B)` | | function | `Function` | `t.Function` | -| arrays | `Array` | `t.array(A)` | | literal | `'s'` | `t.literal('s')` | -| maybe | `A | null` | `t.maybe(A)` | | partial | `Partial<{ name: string }>` | `t.partial({ name: t.string })` | | readonly | `Readonly<{ name: string }>` | `t.readonly({ name: t.string })` | | readonly array | `ReadonlyArray` | `t.readonlyArray(t.number)` | -| dictionaries | `{ [key: A]: B }` | `t.dictionary(A, B)` | -| refinement | ✘ | `t.refinement(A, predicate)` | -| interface | `{ name: string }` | `t.interface({ name: t.string })` | -| tuple | `[A, B]` | `t.tuple([A, B])` | -| union | `A \| B` | `t.union([A, B])` | -| intersection | `A & B` | `t.intersection([A, B])` | +| interface | `interface A { name: string }` | `t.interface({ name: t.string })` | +| interface inheritance | `interface B extends A {}` | `t.intersection([ A, t.interface({}) ])` | +| tuple | `[ A, B ]` | `t.tuple([ A, B ])` | +| union | `A \| B` | `t.union([ A, B ])` | +| intersection | `A & B` | `t.intersection([ A, B ])` | | keyof | `keyof M` | `t.keyof(M)` | -| recursive types | | `t.recursion(name, definition)` | +| recursive types | see [Recursive types](#recursive-types) | `t.recursion(name, definition)` | +| refinement | ✘ | `t.refinement(A, predicate)` | | map | ✘ | `t.map(f, type)` | | prism | ✘ | `t.prism(type, getOption)` | @@ -219,6 +221,8 @@ You can define your own combinators. Let's see some examples ## The `maybe` combinator +An equivalent to `T | null` + ```ts export function maybe( type: RT,