J
J
jsdev12020-08-04 20:31:14
typescript
jsdev1, 2020-08-04 20:31:14

How to deal with objects of different interfaces in TypeScript?

There are two interfaces:

interface IHome {
  a: 1
}
interface IMan {
  b: "1",
  c: Function
}


And there is a function that should be able to work with objects of different interfaces, i.e. with IHome and IMan.
Interfaces do not have common properties and methods, and the union type allows you to work only with common properties and methods

function (param: IHome | Man): number

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2020-08-04
@jsdev1

Use type guard inside a function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question