Answers for "how to use variable as object key in typescript"

10

variable key name js

//You need to make the object first, then use [] to set it.

var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
Posted by: Guest on June-19-2020
0

how to use variable as object key in typescript

var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
Posted by: Guest on March-19-2021
-1

typescript object key type

// For every properties K of type T, transform it to U
function mapObject<K extends string, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U>

const names = { foo: "hello", bar: "world", baz: "bye" };
const lengths = mapObject(names, s => s.length);  // { foo: number, bar: number, baz: number }
Posted by: Guest on August-06-2021

Code answers related to "how to use variable as object key in typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language