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

186
Views
Dealing with strictFunctionTypes and required fields

I've run into a problem with my dynamic data tables. They're a series of configurations for each field. Everything has certain fields (id, createdAt, updatedAt, etc), but some fields are object specific.

I've reproduced this as best as I can below.

This all works as long as everything in UserData or PostData is optional. But we know letting a users email be undefined is completely pointless, in this context.

// The fields we know all objects will have
type RawData = { id: number; }

// The fields of a specific type of object
type UserData = RawData & { email: string, name: string };
type PostData = RawData & { name: string }

// A field config, for dynamic tables or similiar
type Config = {
  getValue: (data: RawData) => string;
}

const ConfigMap: Record<string, Config> = {
  // A field that is only valid for users
  USERNAME: {
    entity: ['USERS'],
    getValue: (data: UserData) => ''
  },
  // A field that is valid for either
  NAME: {
    entity: ['USERS', 'POSTS'],
    getValue: (data: UserData | PostData) => ''
  }
}

The problem is strictFunctionTypes doesn't like this. As long as everything is optional, it's fine. But the second I require something it breaks down.

Is this solvable without breaking strictFunctionTypes?

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!