This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.
Releases
ajv-ts@0.5.0
Minor Changes
cc5ef23: Minor release 0.5 is out!
Installation/Update
npm i ajv-ts@latest # npm
yarn add ajv-ts@latest # yarn
pnpm add ajv-ts@latest # pnpm
bun add ajv-ts@latest # bun
New Features
not, exclude
Now you can mark your schema with not keyword!
Here is a 2 differences between not and exclude.
not method wrap given schema with not
exclude(schema) - add not keyword for incoming schema argument
Example:
import s from "ajv-ts";
// not
const notAString = s.string().not(); // or s.not(s.string())
notAString.valid("random string"); // false, this is a string
notAString.valid(123); // true
// exclude
const notJohn = s.string().exclude(s.const("John"));
notJohn.valid("random string"); // true
notJohn.valid("John"); // false, this is John
// advanced usage
const str = s.string<"John" | "Mary">().exclude(s.const("John"));
s.infer<typeof str>; // 'Mary'
keyof
New function that can be used in a root. Same as keyof T in Typescript.
NOTE: currenty works only with objects only, this behavior will be fixed in future releases.
Example:
import s from "ajv-ts";
const keys = s.keyof(
s.object({
key1: s.string(),
key2: s.object({}),
})
);
type Result = s.infer<typeof keys>; // 'key1' | 'key2'
keys.schema; // { anyOf: [ { cosnt: 'key1' }, {const: 'key2' } ] }
Never
Same as never type in Typescript. JSON-schema equivalent is {not: {}}.
Fixes
s.number() - now generic!
s.boolean() - now generic!
Array
empty schema definition
function can be called without schema definition
import s from "ajv-ts";
// before 0.5
s.array(); // error
// 0.5 and later
s.array(); // OK, deinition is not required anymore!
Improve typescript generics usage. Now you cannot set float or negative values.
Example:
import s from "ajv-ts";
// Before 0.5
s.array(s.number()).minContains(-1); // Typescript was silent
// After 0.5
s.array(s.number()).minContains(-1); // Typescript error: `Argument of type 'number' is not assignable to parameter of type '[never, 'TypeError: "minContains" should be positive integer', "Received: '-1'"]'.`
This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.
Releases
ajv-ts@0.5.0
Minor Changes
cc5ef23: Minor release
0.5
is out!Installation/Update
New Features
not, exclude
Now you can mark your schema with
not
keyword!Here is a 2 differences between
not
andexclude
.not
method wrap given schema withnot
exclude(schema)
- addnot
keyword for incomingschema
argumentExample:
keyof
New function that can be used in a root. Same as
keyof T
in Typescript.NOTE: currenty works only with objects only, this behavior will be fixed in future releases.
Example:
Never
Same as
never
type in Typescript. JSON-schema equivalent is{not: {}}
.Fixes
s.number()
- now generic!s.boolean()
- now generic!Array
empty schema definition
function can be called without schema definition
pushItems
push(append) schema to array(parent) schema.
Example:
minContains/maxContains
Improve typescript generics usage. Now you cannot set float or negative values.
Example:
JS Doc updates
Update and add JS Doc for:
nullable
- updatearray
- updatevalidate
- updateparse
- updatenumber().const()
- updatearray().contains()
- addconst()
- addany()
- updateunknown
- updatecreate
- update