Spread syntax for Map in JavaScript

In my React project (Chat App), I am using redux toolkit, I want to use Map in place of object literal {} as state. chatMap state contains contactId (mongodb _id) as key and chat array as value. something like that – chatMap = { [contactId1]: [chatsArr1], [contactId2]: [chatsArr2] } (chatSlice.js) const initialState = { chatMap:… Read More Spread syntax for Map in JavaScript

How to use an expression in the Object literal key?

I have a switch^ let s = "aaa" switch (true) { case s.includes(‘a’): url = ‘https://a.com/wp-admin/post-new.php’ console.log(url) break case s.includes(‘b’): url = ‘https://b.com/wp-admin/post-new.php’ console.log(url) break default: console.log(‘default’) break } I’m trying to change this to a literal object, but I can’t figure out how to properly specify the s.includes condition as the object key const… Read More How to use an expression in the Object literal key?

Preventing object literals type widening when passed as argument in TypeScript

Is is possible in the lastest TypeScript version to pass an object literal as argument to a function without widening it, and also without using as const in the invocation? link to TS Playground: Example What I currently do is this: function func<T>(value: T): T { return value; }; let test = func({ key: ‘value’… Read More Preventing object literals type widening when passed as argument in TypeScript