If you already have a subscription, you can sign in.
Enjoy free content straight from your inbox 💌
00:00
Within JavaScript only a string number or a symbol can be used as a key within a JavaScript property. Anything else is actually not supported by the JavaScript runtime. And the runtime will actually convert these things into a string, which gives unpredictable results and therefore it is caught at compile time by type script. Now, if you wanted to create a type which could accept any of the valid keys, you could do that with the key of operator and apply that to the any type. And this gives you what you would expect, which is the union of string number and symbol. And we can further verify this by creating a simple variable
00:33
of type wallet key. And you can see that we can only assign a string number or symbol to it. However, you don't need to create this type yourself because this is actually provided by the TypeScript compiler as a part of the standard library definition with the type name, property key. And you can see that we still get that error on the example. And if you hover over the property key, it is exactly what you would expect, which is string number or symbol.