What is Nostr?
Callionica /
npub1emh…q9c5
2024-06-20 09:08:44
in reply to nevent1q…ecxv

Callionica on Nostr: You can treat `any` as `T` implicitly. You can’t treat `unknown[]` as `T` ...

You can treat `any` as `T` implicitly. You can’t treat `unknown[]` as `T` implicitly. That’s why you need the `as any`.

You could move the `any` into your Map. Otherwise you could tell the compiler that the data you are retrieving from the map is expected to be a T by making your function generic on T and using `as T` instead of `as any`.

Ultimately if you store heterogenous data in the map but don’t use `any` there, you’ll need an explicit cast to get back a specific type.
Author Public Key
npub1emhf6ln8qk2xxgdegr45a3xmwwxpsd3d9tpxmzwfa2hey6w8lc9sqlq9c5