i require assistance from the typesafe cult (solved)

type the keys on a const object while preserving their assigned values.
const FileNamesMap: {[key: string]: string[]} = {
'Activity': [
'Following',
'Likes',
],
'Comments': ['Comments'],
'Direct Messages': ['Direct Messages'],
'Profile': ['Profile Info'],
'Videos': ['Videos'],
} as const
const FileNamesMap: {[key: string]: string[]} = {
'Activity': [
'Following',
'Likes',
],
'Comments': ['Comments'],
'Direct Messages': ['Direct Messages'],
'Profile': ['Profile Info'],
'Videos': ['Videos'],
} as const
So like this, but I don't want to give the values a type of string[]. I want the key Activity to literally correspond to the value 'Following', 'Likes'] as const Is this even possible? cause:
The type 'readonly ["Following", "Likes"]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.
The type 'readonly ["Following", "Likes"]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.
4 Replies
Brendonovich
Brendonovich•2y ago
new typescript feature has you covered 😉
const FileNamesMap = {
Activity: ["Following", "Likes"],
Comments: ["Comments"],
"Direct Messages": ["Direct Messages"],
Profile: ["Profile Info"],
Videos: ["Videos"],
} as const satisfies Record<string, readonly string[]>;
const FileNamesMap = {
Activity: ["Following", "Likes"],
Comments: ["Comments"],
"Direct Messages": ["Direct Messages"],
Profile: ["Profile Info"],
Videos: ["Videos"],
} as const satisfies Record<string, readonly string[]>;
chmod
chmodOP•2y ago
omg satisfies was the answer??
Brendonovich
Brendonovich•2y ago
yep
chmod
chmodOP•2y ago
wow ty
Want results from more Discord servers?
Add your server