loading...

re: No Optional Chaining? No Problem. Write Your Own deepGet Function! VIEW POST

TOP OF THREAD FULL DISCUSSION
re: I know another cool trick, using Proxy. function safeGet (obj) { return new Proxy({}, { get(_, prop) { if (prop == '_') // set whatev...
 

You could use ts-optchain, which provides a similar approach using Proxy, but the syntax is actually:

oc(object).foo.bar.foobar("default value");
// object?.foo?.bar?.foobar ?? "dafault value"
 

Nice one! Thanks for sharing!

code of conduct - report abuse