// === Autogenerated stuff from OpenAPI ===
type CreationForFoo = {
id: string
foo_field: string
}
type CreationForBar = {
id: string
bar_field: string
}
type CreateFooBarsPayload = CreationForFoo | CreationForBar
function createFooBars(payload: CreateFooBarsPayload) {
// implemented
}
// === My application types ===
type Foo = {
id: string
fooField: string
}
type Bar = {
id: string
barField: string
}
type FooBar = Data.TaggedEnum<{
Foo: Foo
Bar: Bar
}>
type Payload = {
fooBars: FooBar[]
}
function main(fooBar: FooBar) {
const payload = Data.taggedEnum<FooBar>().$match({
Foo: (foo) => ({
id: foo.id,
foo_field: foo.fooField
}),
Bar: (bar) => ({
id: bar.id,
bar_field: bar.barField,
random_blahblah: "aaa" // Should lead to TS error when calling createFooBars
}),
RandomThing: () => ({ // Should give TS error
randomrandom: "blahblahblah"
})
})(fooBar)
createFooBars(payload); // Should give TS error since there are unexpected things
}
// === Autogenerated stuff from OpenAPI ===
type CreationForFoo = {
id: string
foo_field: string
}
type CreationForBar = {
id: string
bar_field: string
}
type CreateFooBarsPayload = CreationForFoo | CreationForBar
function createFooBars(payload: CreateFooBarsPayload) {
// implemented
}
// === My application types ===
type Foo = {
id: string
fooField: string
}
type Bar = {
id: string
barField: string
}
type FooBar = Data.TaggedEnum<{
Foo: Foo
Bar: Bar
}>
type Payload = {
fooBars: FooBar[]
}
function main(fooBar: FooBar) {
const payload = Data.taggedEnum<FooBar>().$match({
Foo: (foo) => ({
id: foo.id,
foo_field: foo.fooField
}),
Bar: (bar) => ({
id: bar.id,
bar_field: bar.barField,
random_blahblah: "aaa" // Should lead to TS error when calling createFooBars
}),
RandomThing: () => ({ // Should give TS error
randomrandom: "blahblahblah"
})
})(fooBar)
createFooBars(payload); // Should give TS error since there are unexpected things
}