superstruct
superstruct copied to clipboard
Generate struct from TS interface
Hi everyone I have some complex Typescript interfaces from a 3rd party library and I would like to use superstruct to validate at runtime.
Is there a way I can generate a superstruct schema from a Typescript interface?
eg
// user.ts
interface User {
id: number
name: string
}
/* Run some node command */
// output/superstruct-user.ts
const User = type({
id: number(),
name: string(),
})
Sounds good idea. But I think it only can be done creating a typescript plugin. Similar than kimamula/ts-transformer-keys does
Wow it would be a nice feature. @ianstormtaylor is it possible to mark as a feature request?
That would be a pretty heavy lift for this lib. While nice, it would involve walking a TypeScript AST, evaluating each node, and building a Node AST with something like acorn on the fly. As @JoniJnm mentioned, that would be better off a separate plugin.