Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JTD schemas do not support coerceTypes option #1724

Open
riker09 opened this issue Jun 28, 2021 · 4 comments
Open

JTD schemas do not support coerceTypes option #1724

riker09 opened this issue Jun 28, 2021 · 4 comments

Comments

@riker09
Copy link

riker09 commented Jun 28, 2021

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:

Bildschirmfoto von 2021-06-28 09-13-51

@epoberezkin
Copy link
Member

JTD schemas do not support type coercion.

@epoberezkin epoberezkin changed the title Unable to use coerceTypes option JTD schemas do not support coerceTypes option Aug 1, 2021
@epoberezkin epoberezkin transferred this issue from ajv-validator/ajv-formats Aug 1, 2021
@egorkel-altexsoft
Copy link

Why?

@curvedriver
Copy link

curvedriver commented May 9, 2022

@epoberezkin,
Do you have any plans to support the coerceTypes option or is this not possible in case of JTD?

@fabianeichinger
Copy link

fabianeichinger commented Nov 18, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants