Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript key options from array values

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #typescript #key #options #array #values
ADD COMMENT
Topic
Name
8+9 =