1

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
}

1 Answer 1

1

Turns out all we need is the typeof type operator:

export const FormFieldDefaults = {
  firstName: '',
  lastName: '',
  dateOfBirth: ''
}

export type FormFields = typeof FormFieldDefaults
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.