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

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

Open
josh-hemphill opened this issue Feb 16, 2022 · 0 comments

Comments

@josh-hemphill
Copy link

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 #1489
But the docs still say

type inference is not supported for JTDDataType yet
-utility-type-for-jtd-data-type

For example, something like

function helper<T extends JTDSchemaType>(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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant