4 ms·
Yes! They're called discriminated unions: https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#discriminated-unions https://www.typesc
by fwouts 4y ago
Yes! They're called discriminated unions: https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#discriminated-unions https://www.typescriptlang.org/docs/handbook/typescript-in-5...
Here's an example: https://tseditor.fwouts.com/?t=ZXhwb3J0IHR5cGUgVmFsdWUgPSBVc2VyIHwgQWRtaW47CgpleHBvcnQgdHlwZSBVc2VyID0gewogIGtpbmQ6ICJ1c2VyIjsKICBuYW1lOiBzdHJpbmc7Cn0KCmV4cG9ydCB0eXBlIEFkbWluID0gewogIGtpbmQ6ICJhZG1pbiI7CiAgcm9sZXM6IEFkbWluUm9sZVtdCn0KCmV4cG9ydCBlbnVtIEFkbWluUm9sZSB7CiAgUkVBRCwKICBXUklURSwKICBNQU5BR0UKfQ%3D%3D https://tseditor.fwouts.com/?t=ZXhwb3J0IHR5cGUgVmFsdWUgPSBVc...