Skip to content

Commit

Permalink
Merge pull request #1091 from thetric/typescript-usage-note
Browse files Browse the repository at this point in the history
docs(readme): add usage notes for TypeScript users
  • Loading branch information
epoberezkin committed Feb 17, 2020
2 parents 75aa5fd + 7b574e7 commit c1c0ba7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -131,7 +131,11 @@ Try it in the Node.js REPL: https://tonicdev.com/npm/ajv
The fastest validation call:

```javascript
// Node.js require:
var Ajv = require('ajv');
// or ESM/TypeScript import
import Ajv from 'ajv';

var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true}
var validate = ajv.compile(schema);
var valid = validate(data);
Expand Down Expand Up @@ -165,6 +169,10 @@ The best performance is achieved when using compiled functions returned by `comp

__Please note__: every time a validation function or `ajv.validate` are called `errors` property is overwritten. You need to copy `errors` array reference to another variable if you want to use it later (e.g., in the callback). See [Validation errors](#validation-errors)

__Note for TypeScript users__: `ajv` provides its own TypeScript declarations
out of the box, so you don't need to install the deprecated `@types/ajv`
module.


## Using in browser

Expand Down

0 comments on commit c1c0ba7

Please sign in to comment.