在浏览一些打字稿代码时,@ng-bootstrap我找到了pipe(|)运算符.
export declare const NGB_PRECOMPILE: (typeof NgbAlert | typeof NgbTooltipWindow)[];
Run Code Online (Sandbox Code Playgroud)
|在打字稿中使用pipe()运算符有什么用?
Ale*_* L. 72
这在typescript中称为union类型.
联合类型描述的值可以是几种类型之一.
看看这个例子:
class Test1 {
public a:string
}
class Test2 {
public b:string
}
class Test3 {
}
let x: (typeof Test1 | typeof Test2)[];
x = [Test1]; //ok
x = [Test1, Test2]; //ok
x = [Test3]; //compilation error
Run Code Online (Sandbox Code Playgroud)
cha*_*ham 11
在JavaScript中,管道运算符表示'或'.因此,在此上下文中,它表示允许的任何声明类型.也许很容易理解与原始类型的联合:
let x: (string | number);
x = 1; //ok
x = 'myString'; //ok
x = true; //compilation error for a boolean
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29666 次 |
| 最近记录: |