Axel Rauschmayer on Nostr: #TypeScript helper function to safely access objects used as dictionaries: function ...
#TypeScript helper function to safely access objects used as dictionaries:
function getOwn<K extends string | number | symbol, V>(obj: Record<K, V>, key: K): undefined | V {
if (!Object.hasOwn(obj, key)) {
return undefined;
}
return obj[key];
}
Published at
2024-01-24 13:50:34Event JSON
{
"id": "6426c090a0f4acefd4f5584cd8a02f135f6f72e406c9cf240bcd825b13b30dbe",
"pubkey": "f757585053520644e2ce9e8c1dbb9dccaedb41a58cec71ac4e94257c6ce1e52b",
"created_at": 1706104234,
"kind": 1,
"tags": [
[
"t",
"typescript"
],
[
"proxy",
"https://fosstodon.org/users/rauschma/statuses/111811247120898158",
"activitypub"
]
],
"content": "#TypeScript helper function to safely access objects used as dictionaries:\n\nfunction getOwn\u003cK extends string | number | symbol, V\u003e(obj: Record\u003cK, V\u003e, key: K): undefined | V {\n if (!Object.hasOwn(obj, key)) {\n return undefined;\n }\n return obj[key];\n}",
"sig": "0835fb79be909a59fa430cbdf6324b57c0926d96585de507c9d1ac8b7ef1d44ca476698765bc3a4273ccf97fc51244cb3f52bd97090b44664094ba2609758d61"
}