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

169
Views
TypeScript - Distributive conditional types

Talk is cheap,show the code! By the way, the version of ts I am testing is 4.6.4

type ITypeA = ((args: { A: any }) => any) | ((args: { B: any }) => any);

type Test<T> = T extends (args: infer A) => any ? A : never;

// type Result1 = {
//     A: any;
// } | {
//     B: any;
// }
type Result1 = Test<ITypeA>;

// type Result2 = {
//     A: any;
// } & {
//     B: any;
// }
type Result2 = ITypeA extends (args: infer A) => any ? A : never;

Result1 may use 'distributive conditional types' rule in ts, so type Result1 = { A: any;} | { B: any;}.

My question is why does Result2 not apply this rule? Is there any difference between them?

Playground Link

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please see docs

When conditional types act on a generic type, they become distributive when given a union type. For example, take the following:

There is a requirement, you need act on generic.

Result2 acts on known types, there is no generic, whereas Result1 uses Test which in turn uses generic T

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!