2

I just want to have an object with dynamic properties like ( get , post, put )

type methodNames = "get" | "post" | "put";

interface toFetch {
    target:string,
    from: string
  }

type CommonApiQuery = Record<methodNames, toFetch[]>

I want the CommonAPIQuery to allow objects something like below:

const lookup : CommonApiQuery = {
  get: [{target:"students",from:"id"}]
}

But its expecting properties "post" and "put" also. I just want to have atleast one of the defined properties in methodNames, but should throw error when no property from methodNames is defined. How to achieve that ?

Hari Warshan
  • 153
  • 1
  • 8
  • 1
    You can use `AtLeastOne` from the answer to [the other question](https://stackoverflow.com/questions/48230773/how-to-create-a-partial-like-that-requires-a-single-property-to-be-set) and make [this](https://tsplay.dev/WvpJAN) solution, or modify it with [this answer](https://stackoverflow.com/questions/57683303/how-can-i-see-the-full-expanded-contract-of-a-typescript-type) to get [this](https://tsplay.dev/WyvG6w). – jcalz May 31 '21 at 04:14

0 Answers0