type Aa = {a: string}
type T2 = Aa & ({prefixB: string} | {b: string})
const foo: T2 = {
a: "a",
b: "b"
}
foo.a // a
foo.b // b
foo.prefixB // Property 'prefixB' does not exist
const foo2: T2 = {
a: "a",
prefixB: "prefixB"
}
foo2.a // string
foo2.prefixB // prefixB
foo2.b // Property 'b' does not exist
i think this is work
update
type Aa = {a: string}
type B = {
c: string
}
type T2 = Aa & ({prefixB: B} | {b: B})
const foo: T2 = {
a: "a",
b: {
c: "obj"
},
}
foo.a // a
foo.b // { c: "obj" }
foo.prefixB // Property 'prefixB' does not exist
const foo2: T2 = {
a: "a",
prefixB: {
c: "obj"
}
}
foo2.a // a
foo2.prefixB // { c: "obj" }
foo2.b // Property 'b' does not exist
const foo3: T2 = {
a: "a",
prefixB: {
c: "obj"
},
b: {
c: "obj"
}
}
foo3.a // a
foo3.prefixB // Property 'prefixB' does not exist
foo3.b // Property 'b' does not exist