branded types cannot be used for narrowing. Say that we have a
TagA:
type: string
enum:
- a
A:
oneOf:
- TaggedA
- ...
TaggedA:
type: object
properties:
tag:
$ref: TagA
then typescript does not narrow by the tag field as the tag value gets branded as a top level scalar definition.
function foo(a: A): null | Value {
if (tagged.tag === 'a') {
return a.value;
}
return null;
}
instead need to use instanceof TaggedA or work with ShapeOfTaggedA. Or if possible define TaggedA as
TaggedAd:
...
properties:
tag:
type: string
enum: a
...