ajv-validator / ajv-validator/ajv

What needs to happen before we can get simultaneous TS inference and validation for JTD schemas?

Abierto
#1,902 0 comentarios 4 reacciones 0 asignados Ver en GitHub
typescript
Lenguaje dominante
TypeScript
Estrellas
14.8k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**What version of Ajv are you using? Does the issue happen if you use the latest version?**
8

The last I've seen of work on the `JTDSchemaType` and `JTDDataType` is in https://github.com/ajv-validator/ajv/issues/1489
But the docs still say

> type inference is not supported for JTDDataType yet
-[utility-type-for-jtd-data-type](https://ajv.js.org/guide/typescript.html#utility-type-for-jtd-data-type)

**For example, something like**

```typescript
function helper(schema: T) {return schema};
const mySchema = helper({
properties: {
num: {type: "float64"},
nullableEnum: {enum: ["v1.0", "v1.2"], nullable: true},
values: {values: {type: "int32"}},
},
optionalProperties: {
optionalStr: {type: "string"},
},
invalidKey: something // <-- invalid provides an inferred type error in your IDE
})
// And still be able to get inferred data type when the schema is type validated
const data = ajv.compile(mySchema)
let num = data.num // inferred to be number
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.