Skip to content

Instantly share code, notes, and snippets.

@daffl
Last active January 16, 2022 19:32
Show Gist options
  • Save daffl/7728140456ffdfa96ec858616a99a9c2 to your computer and use it in GitHub Desktop.
Save daffl/7728140456ffdfa96ec858616a99a9c2 to your computer and use it in GitHub Desktop.
Feathers schema example
import { schema, Infer } from '@feathersjs/schema'
export const userSchema = schema({
$id: 'User',
type: 'object',
additionalProperties: false,
required: ['email', 'password'],
properties: {
id: { type: 'number' },
email: { type: 'string' },
password: { type: 'string' }
}
} as const)
export type User = Infer<typeof userSchema>
// type User = {
// id?: number;
// email: string;
// password: string;
// }
@bitflower
Copy link

Hi David, so that's all that would be needed to get typescript interfaces out of json-schema?

@daffl
Copy link
Author

daffl commented Jan 16, 2022

@bitflower Correct. You can already use this with the current prerelease. More detailed documentation can be found at https://dove.docs.feathersjs.com/api/schema (which also shows how to do association and extension).

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