Car*_*lin 41 types ampersand typescript
在此类型定义文件的第60359行,有以下声明:
type ActivatedEventHandler = (ev: Windows.ApplicationModel.Activation.IActivatedEventArgs & WinRTEvent<any>) => void;
Run Code Online (Sandbox Code Playgroud)
&
在这种背景下,印记意味着什么?
Wil*_*een 53
例子:
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;
Run Code Online (Sandbox Code Playgroud)
bas*_*rat 36
&
在类型位置意味着类型交集.
https://www.typescriptlang.org/docs/handbook/advanced-types.html#intersection-types
归档时间: |
|
查看次数: |
10492 次 |
最近记录: |