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

109
Views
How can I make typescript 'type tip' more limited in the code?

typescript tip: step is any type. This is too bad!

How do I optimize?

export function foo (isActive:boolean) {
  let step
  if (isActive) {
    step = [
      '1ICK750', '2IYE230', '3CI0320', '3CI0720', '4PGC938'
    ] as const
  } else {
    step = [
      'are', 'by', 'sea', 'seashells', 'she', 'shore', 'the', 'zoo'
    ] as const
  }
  // ...more

  // typescript tip: step is any type.This is too bad!
  return step
}

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

0

you can make the step like this

let step: string[] = []

now your return type will also be a string of array.

about 4 years ago · Juan Pablo Isaza Report

0

Define it using the conditional operator instead.

const step = isActive
    ? ['1ICK750', '2IYE230', '3CI0320', '3CI0720', '4PGC938'] as const
    : ['are', 'by', 'sea', 'seashells', 'she', 'shore', 'the', 'zoo'] as const;
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!