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

160
Views
Typescript function that returns modified object with correct types

this might sound stupid but I want to know If I can use a function that returns a modified object and display the correct type in return.

The input is as followings

{
  enable: { label: "Enable", value: false },
  castShadow: {
           label: "Intensity",
           value: 25,
           condition: currentValue.type === "Circle"}
}

As for the return value, I want to modify it to be just like this

{enable:true,castShadow:40}

To final goal I want to achieve is this one if it is possible

  const { ConfigRenderer, enable, castShadow} = useConfig({
        enable: { label: "Enable", value: false },
         castShadow: {
           label: "Intensity",
           value: 25,
           condition: currentValue.type === "Circle"}
  });
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can achive this using mapped types and conditional types like this:

type ValuesOf<T, P = 'value'> = { 
   [K in keyof T]: P extends (keyof T[K]) ? T[K][P] : never 
};

function useConfig<T>(param: T): ValuesOf<T> {
   // ...
}

The ValuesOf type is a mapped type that will contain all keys of type T but maps them to the type of the property P inside type T (or to never, if property P does not exist on type T). In the code above P is defaulted to 'value' but you could as well use any other property name or even a union of property names.

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