Wartość kluczowa pary TypeScript
var item: {[key: string]: number}
Iron Chicken
var item: {[key: string]: number}
let indexedArray: {[key: string]: number}
let indexedArray: {[key: string]: number} = {
foo: 123,
bar: 456
}
indexedArray['foo'] = 12;
indexedArray.foo= 45;
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