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

99
Views
Interface to map values of 2 objects in Typescript

I have 2 objects objA and objB

I have a function which accepts value from objB and key from objA.

const objA = {
  a:"a",
  b:"b"
}
const objB = {
  a:"a",
  b:"b"
}
checkValues = (type:string,key:keyof typeof objA)=>{
 return  objA[key] === type;
}

checkValues("A",objA.a)

But getting type error Argument of type 'string' is not assignable to parameter of type '"a" | "b"'

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

0

Defining your function like that it can only check the entries of the object(so 'a' | 'b'), instead, you calling the function passing objA.a which instead refers to the value of the property a on the object.

What you can do is:

//Calling the function and passing only 'a' or 'b'
checkValues("A", 'a');
checkValues("A", 'b');
//Declaring object properties with types through the use of interfaces:
interface MyObj {
    a: 'a' | 'b';
    b: 'a' | 'b';
}

const objA: MyObj = {
  a:"a",
  b:"b"
}
const objB: MyObj = {
  a:"a",
  b:"b"
}

You haven't really specified what you need so this is what i would probably do, hope it will help

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!