On line 60359 of this type definition file, there is the following declaration:
type ActivatedEventHandler = (ev: Windows.ApplicationModel.Activation.IActivatedEventArgs & WinRTEvent<any>) => void;
What does the &
sigil mean in this context?
答案 0 :(得分:30)
&
in a type position means type intersection.
https://www.typescriptlang.org/docs/handbook/advanced-types.html#intersection-types
答案 1 :(得分:4)
示例:
type dog = {age: number, woof: Function};
type cat = {age: number, meow: Function};
// Type weird is an intersection of cat and dog
// it needs to have all properties of them combined
type weird = dog & cat;
const weirdAnimal: weird = {age: 2, woof: () => {'woof'}, meow: () => {'meow'}}
interface extaprop {
color: string
}
type catDog = weird & extaprop; // type now also has added color
const weirdAnimal2: catDog = {age: 2, woof: () => {'woof'}, meow: () => {'meow'}, color: 'red'}
// This is different form a union type
// The type below means either a cat OR a dog
type dogOrCat = dog | cat;