ajv-validator / ajv-validator/ajv

Typescript parser/serializer type is unknown when using JTD definitions

Aperta
#2,165 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement typescript
Lingua principale
TypeScript
Stelle
14.8k
Fork
1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

8.11.2 (latest version as of issue creation)

Using Typescript 4.8.4

**Ajv options object**

Using defaults

**Your code**

Using refs with JTD does not produce a type safe object when using `compileParser` or `compileSerializer`. The resulting object is always of type `unknown` in Typescript (this also does not work with recursive refs)

```javascript
// using the schema provided in the documentation https://ajv.js.org/json-type-definition.html#ref-schemas
const schema: JTDSchemaType<{val: number}, {num: number}> = {
definitions: {
num: {type: "float64"},
},
properties: {
val: {ref: "num"},
},
}

const ajv = new Ajv()
const parse = ajv.compileParser(schema)

const result = parse(data) // type should be {val: number}, but is unknown
```

**What results did you expect?**
`compileParser` and `compileSerializer` should produce type-safe results.

**Are you going to resolve the issue?**
Unsure how to resolve the issue.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.