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

84
Views
TypeScript Optional Sub-Properties

So I know that there is a way to create a type-alias to have properties such as answer I have seen from another user in this post (Typescript interface optional properties depending on other property) like below:

type Sample = {
  key1: true,
  key2?: string,
  key3: number
} | {
  key1: false,
  key2?: string,
  key3?: never
}

but how would I do it if the dependent properties are inside (as in, both key2 and key3 belong to key1, but key3 would exist only if key2 is true)? Would it be something like this:

type Sample = {
  key1: {
  key2?: true,
  key3: number
 }
} | {
  key1: {
  key2?: false,
  key3?: never
 }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

An option is to just make the distinction inside like this:

type Sample = {
  key1: {
  key2?: true,
  key3: number
 } | {
  key2?: false,
  key3?: never
 }
}

Your code actually works too

about 4 years ago · Juan Pablo Isaza Report
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!