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

Feature Request: compile to standalone TypeScript, or generate typings #192

Open
thw0rted opened this issue Nov 17, 2021 · 1 comment
Open

Comments

@thw0rted
Copy link

I'm trying to validate JSON against a TypeScript interface. I used https://github.com/vega/ts-json-schema-generator to generate a JSON schema from the interface, then used ajv-cli to produce a standalone validator from the schema. The validator is an ES module with a default export function which takes the output of JSON.parse and returns true if the data is valid, or sets an errors property on the function and returns false otherwise.

I can write my own typings to describe this generated module, but it would be nice if the CLI could generate TypeScript code directly (with a flag like -code-ts), or add JSDoc annotations from which TypeScript can infer type information (at least for the one exported function), or create a .d.ts file describing the export(s) in the output directory (when run with a -o flag).

As an aside, if there's an easier way to get from what I have (TS interface) to what I want (runtime validation function), I'm happy to take other suggestions.

@iebold
Copy link

iebold commented Aug 2, 2023

I would just add that setting the errors property on the function itself is a pretty odd design choice especially since the function takes a second optional argument anyhow.

How do you describe the errors in Typescript?

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

No branches or pull requests

2 participants