Skip to content

Commit 5c5399e

Browse files
committed
docs(README.md): document ExtractType
1 parent 5dd9ee0 commit 5c5399e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,35 @@ Logs a warning to the console if `input` isn't the correct type.
316316
### `toString(): string`
317317

318318
Returns a string representation of this type (using TS type syntax in most cases).
319+
320+
## `t.ExtractType<T extends Type<any>>`
321+
322+
Gets the TypeScript type that a validator type accepts. For example:
323+
324+
```ts
325+
import * as t from 'typescript-validators'
326+
327+
const PostValidator = t.simpleObject({
328+
author: t.simpleObject({
329+
name: t.string(),
330+
username: t.string(),
331+
}),
332+
content: t.string(),
333+
tags: t.array(t.string()),
334+
})
335+
336+
type Post = t.ExtractType<typeof PostValidator>
337+
```
338+
339+
Hover over `Post` in the IDE and you'll see, voilà:
340+
341+
```ts
342+
type Post = {
343+
author: {
344+
name: string
345+
username: string
346+
}
347+
content: string
348+
tags: string[]
349+
}
350+
```

0 commit comments

Comments
 (0)