ajv
ajv copied to clipboard
JTD schemas do not support coerceTypes option
I'm using TypeScript v4.3.4 and I am unable to use the coerceTypes option when constructing the Ajv instance.
import Ajv from 'ajv/dist/jtd';
const ajv = new Ajv({ coerceTypes: true });
This is a screenshot of the error I get in VSCodium v1.57.1:

JTD schemas do not support type coercion.
Why?
@epoberezkin,
Do you have any plans to support the coerceTypes option or is this not possible in case of JTD?
Ran into the same issue today. Really happy with JTD type generation, but working against an inconsistent API makes coercion kind of a hassle.
I wrote a small helper to wrap Ajv validator and do simple coercion. It's not extensively tested, but I'll update it if I run into bugs until this is an official feature: https://gist.github.com/fabianeichinger/f9bad3ee17d637ac3778448d0fb0f528