Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
How to infer object with generic items

I have an object like this and infer types using settingToType helper:

    enum SettingType {
      Departures = 'departures',
      Dashboards = 'bookings_dashboards',
      MainNumber = 'main_number_is_booked_spots',
    }

    type Setting<P> = {
      type: SettingType
      payload: P
      component: Component<{
        modelValue: P
        'onUpdate:modelValue'?: (payload: P) => void
      }>
      validator: ZodType<P>
    }

    const settingToType = <P>(s: Setting<P>) => s

    export const settingsInfo = {
      [SettingType.Departures]: settingToType({
        type: SettingType.Departures,
        component: DeparturesListSelectorVue,
        payload: [],
        validator: array(number()),
      }),
      [SettingType.Dashboards]: settingToType({
        type: SettingType.Dashboards,
        component: BookingsDashboardSelectorVue,
        payload: [],
        validator: array(number()),
      }),
      [SettingType.MainNumber]: settingToType({
        type: SettingType.MainNumber,
        component: AvailableBookedSpotsSelectorVue,
        payload: false,
        validator: boolean(),
      }),
    }

How to replace multiple usage of settingToType with one function which infers all object at once?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!