How to get TS Type from Adonis schema? #3365
-
I would like to somehow get the type of interface created by const newPostSchema = schema.create({
title: schema.string(),
kind: schema.enum(['article', 'note'] as const),
})
type newPostType = typeof newPostSchema This is not needed for validation, but to improve DX and intellisense: function preparePost(): newPostType {
return {
title: 'foo',
kind: 'bar' // TS2322: Type '"bar"' is not assignable to type '"article" | "note"'.
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
RomainLanz
Nov 25, 2021
Replies: 1 comment
-
Hey @cawa-93! 👋🏻 You can export it using the following. export type NewPostValidatorData = NewPostValidator['schema']['props']
class NewPostValidator {
// ...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
cawa-93
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @cawa-93! 👋🏻
You can export it using the following.