Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add element to typescript Record<>

I have a Record set up like this: let myRecord = Record<String, Set<String>>

How can I add an element to a set inside the record? I have tried the following without success:

let key = "key";
let stringToAdd = "stringToAdd";
myRecord[key].add(stringToAdd);
like image 710
skew Avatar asked Sep 12 '25 13:09

skew


1 Answers

You can use the square brackets [] and an assignment to add elements to the record.

let mySet: Set<string> = new Set();
mySet.add("stringToAdd");

let myRecord: Record<string, Set<string>> = {};

myRecord["key"] = mySet;    // <--- Like this
like image 189
SørenHN Avatar answered Sep 15 '25 03:09

SørenHN