confuse about union and intersection type on typescript

19 Views Asked by At
interface Bird {
    fly(): void;
}

interface Fish {
    swim(): void;
    layEggs(): void;
}

type a = keyof (Bird & Fish) // 'fly' | keyof Fish 
type b = keyof Bird | keyof Fish // 'fly' | keyof Fish
type d = keyof Bird & keyof Fish // never

above code, I don't get it. I read typescript official document. but I still dont.

Union and intersection type in structual typing are different from meaning we usually understand in common.

Can you explain why type 'a', 'b', and 'c' have that types?

I expect those three types below.

type a = keyof (Bird & Fish) // never
type b = keyof Bird | keyof Fish // 'fly' | keyof Fish
type d = keyof Bird & keyof Fish // never

0

There are 0 best solutions below