Type-safe language programmers: "Look what they need just to mimic a fraction of our power."
I name it key instead of index. { [key:string] : unknown }
Deno helped me a lot to learn TypeScript and avoid some bad practices such as this one
For a split second I read "Stop using TypeScript"
thanks kyle, keep with the snippets of TS
you should mention the `object` (note lowercase) this is the most generic pure object you can specify, usually useful it you're extended a generic. function <T extends object>foo (bar: T) { return Object.keys(bar) }
please make more and more shorts. I love your content
This! Thanks, Kyle
The title made me think for a moment there was a trick in TS to get rid of the block scope delimiters "{" "}" lol
Programmer: tells the language that the argument should be an object. Also programmer: passes a Date, which is by definition an object "Woahh why is the labguage allowed this?"
Super helpful! Relaxes my brain to think of it this way
Record<string, unknown> won't exclude arrays though. If you want to exclude arrays, you'll need to do `Record<symbol, unknown>`. There are a few small corner cases where `Record<symbol, unknown>` is too strict, but those don't come up much in user-land.
I've been all up in Record<string, unknown> in the past months. It seems cleaner to my eyes for some reason than the key index approach (2nd version he showed).
Record<string, string>
Also you can still use it, its a great way to tell that something is anything but non nullable
These shorts are awesome, goat js/ts content creator
Great shorts normally but I never bump into this issue, which is confusing as you say "by far the most common issue". If it's being passed like that its normally more defined like as an interface, or as you recommend a type. I never go near the Object type directly.
Doing “Record<string, unknown>” also works
I love the record syntax over the 2nd one
@nomadshiba