Reputation: 25347
I wanted to do some something similar to this: https://stackoverflow.com/a/45777530/565877
But I'm not working with any sort of real database schema, I just have a simple object of field names and their default values, like so:
export const FormFieldDefaults = {
firstName: '',
lastName: '',
dateOfBirth: ''
}
I want to generate this respective type:
export type FormFields = {
firstName: string
lastName: string
dateOfBirth: string
}
Upvotes: 1
Views: 204
Reputation: 25347
Turns out all we need is the typeof
type operator:
export const FormFieldDefaults = {
firstName: '',
lastName: '',
dateOfBirth: ''
}
export type FormFields = typeof FormFieldDefaults
Upvotes: 1