create stricter type
what's the right way to create a type using the actual field names of an object that is currently
{ [x:string]: Foo }
? will keyof typeof
actually do the magic?15 Replies
nope,
keyof typeof table
gives string | number
instead of the list of keysIf you have an object, you can use something like this:
keyof typeof
should give you the keys though
Hm, { [x:string]: Foo }
looks odd though, you indeed get string/numberI want to programmatically add fields to the object and then turn it into a strict type but as soon as I give a type to the target object it sticks permanently
either { [x:string]: Foo } or Record<string,Foo>
e.g.
even being pretty static I just can't make a keys type
my other use-case composes keys based on the keys of one of the arguments
https://github.com/poupe-ui/poupe/blob/main/packages/theme-builder/src/colors.ts#L61
and https://github.com/poupe-ui/poupe/blob/main/packages/theme-builder/src/colors-data.ts#L111 for the above paste
joe_black_unlucky has been warned
Reason: Posted an invite
I didn't really want to invite you to another discord, just suggesting that you should maybe go ask at a typescript community, this is more of a nuxt centered community
And then my 2 cents: Don't get bogged down with perfectly typing everything, while you are spending hours figuring this out your productivity is zero and solving this is also zero toward completing any task, perfectly typing things does not solve anything. Unless you work for a big coporate that doesn't mind tasks taking weeks to complete
any recommended discord server focused on typescript? it's quite annoying the discussion channels got closed here
It's not a blocker indeed, mostly curiosity. but I am a strong-typed systems developer (C,Go) moving out of my comfort zone a bit trying to learn from vue/nuxt devs how to make front-end stuff "the right way" 🤷♂️
I got a warning from the mods sharing a link, just google for typescript discord server, there is one
thank you!
nah, that was automod
maybe try https://discord.com/invite/typescript
That's the link I shared and got automodded 🙂
I know 😄 - Discord invite spam is too strong nowadays
thank you, I recently cancelled my discord subscription and not I'm being told I can't join more servers 😭 frustratingly it doesn't tell me how many I need to leave 😕 I may just create another account 😅
max is 50 or so I think
I never thought that as a factor to get Nitro
so, the answer is declaring the object using
satisfies
Interesting, I should look into that