Answers for "typescript array with allowed object keys"

4

typescript array with allowed object keys

const keyOptions = ["name", "gender", "address"] as const;
type TCustomKeys = { [key in typeof keyOptions[number]]: any };

const obj: TCustomKeys = {
  name: "James",
  gender: "M",
  address: "1 First Rd"
}; // no errors, and intellisense working
Posted by: Guest on March-09-2022

Code answers related to "typescript array with allowed object keys"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language