N
N
Nikolai2021-12-31 10:30:14
typescript
Nikolai, 2021-12-31 10:30:14

How to get only fields of the same type from an object in Typescript?

type A = {
    a: number
}
  
type B = {
    b: number
}
  
type C = {
    c: number
}
  
interface ABC extends A, B, C {
    abc: number
}  

const obj: ABC = {
    a: 1,
    b: 2,
    c: 3,
    abc: 4
}

const objA: A = obj


How to make objA have only "a" field?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question