#defacto way to check union types and do things based on result
6 messages · Page 1 of 1 (latest)
6 messages · Page 1 of 1 (latest)
I have a function with the following signature
static new(bucket: Bucket, key: string): Cas | Error {
I want to call it and then do things based on whether the return type is Cas or Error. Is this possible?
Cas is a class and Error is another union type
!hb narrowing
const result = example.new(bucket, key);
if(result instanceof Cas) {
// do stuff with `result: Cas`
}
else {
// do stuff with `result: Error`
}
thank you