ajv-validator / ajv-validator/ajv
What needs to happen before we can get simultaneous TS inference and validation for JTD schemas?
- Vorherrschende Sprache
- TypeScript
- Sterne
- 14.8k
- Forks
- 1k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
**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
```
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.