Answers for "typescript key options from array values"

1

typescript key value array

let indexedArray: {[key: string]: number}

let indexedArray: {[key: string]: number} = {
    foo: 123,
    bar: 456
}

indexedArray['foo'] = 12;
indexedArray.foo= 45;
Posted by: Guest on October-15-2020
4

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
Posted by: Guest on March-09-2022

Code answers related to "typescript key options from array values"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language