Branded Literal Types and Exhaustivity Checking Issue in TypeScript

Hey 👋 I'm trying to understand branded literal types and exhausitivity checking. When I define literal type without it being branded, exhaustivity checking works fine:

const FooBar = Schema.Literal('foo', 'bar');
type FooBar = typeof FooBar.Type;

function match(foobar: FooBar): string {
    switch (foobar) { // If either case is missing, I get compile error
        case 'foo': return "foo"
        case 'bar': return "bar"
    }
}


If I adjust the type to be branded:
const FooBar = Schema.Literal('foo', 'bar').pipe(Schema.brand('FooBar'));


I get this error on match function: Function lacks ending return statement and return type does not include 'undefined'.. Any ideas how to get branded types to preserve exhaustivity properties of literal types?
Was this page helpful?