#how to discriminate intersection ?

1 messages · Page 1 of 1 (latest)

vagrant pondBOT
#
nnry#0

Preview:```ts
// assume more properties than these...
interface A {
a: string
}

interface B {
b: number
}

type X = A & B

function update<K extends keyof X>(key: K, value: X[K]) {
// If key is part of 'A'
//...
// Else if key is part of 'B'
//...
...```

tranquil reef
#
if (key === 'a') {
  // A
}
if (key === 'b') {
  // B
}