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

328
Views
typescript: Derive types from Conditional Types

Typescript supports Conditional Types. But when I try to set value of op as string, it gives me error, how do I check the type and assign value?

export const t = <IsMulti extends boolean = false>(): void => {
    const value = 'test';
    type S = string;
    type D = IsMulti extends true ? S[] : S;
    const op: D = value;
    console.log(op);
};

Error: Type 'string' is not assignable to type 'D'.

I have even tried adding a parameter of same type IsMulti and adding check based on it

export const t = <IsMulti extends boolean = false>(isMulti: IsMulti): void => {
    const value = 'test';
    type S = string;
    type D = IsMulti extends true ? S[] : S;
    if (!isMulti) {
        const op: D = value;
        console.log(op);
    }
};

still it gives the same error. enter image description here

over 4 years ago · Santiago Trujillo
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!