1

I have an interface like the following:

interface Cat {
  age? : number
  name? : string
}

with the following scenario:

function getAge(cat: Cat) {
  // ...
}

const catWithAge = getAge({}) // this is ok according the Cat interface

What I would like to do is the function getAge not to accept an empty object.

I would like to have at least one key passed in the object (doesn't matter which one).

What should I change in order to achieve this?

L. Pier Roberto
  • 513
  • 1
  • 6
  • 20
  • See the answer to the other question, code example looks like [this](https://tsplay.dev/m35KAw) – jcalz Feb 11 '22 at 17:40
  • Maybe a duplicate of https://stackoverflow.com/questions/40510611/typescript-interface-require-one-of-two-properties-to-exist – treecon Feb 11 '22 at 17:40

0 Answers0