[英]What does “…”[] mean in Typescript?
我正在使用Typescript来配置 webpack。 当我配置module.rules
时,我检查了types.d.ts
以查看rules
定义。 我看到这句话:
/**
* An array of rules applied for modules.
*/
rules?: (RuleSetRule | "...")[];
我想知道 Typescript 中的"..."[]
是什么意思
RuleSetRule
是一个 object :
declare interface RuleSetRule {
/**
* Match the child compiler name.
*/
compiler?:
| string
| RegExp
| {
... lots of lines
而"..."
是纯字符串类型。 通过将它们括在括号中并在它们之间交替使用|
,你会得到一个匹配一个或另一个的类型(object 或字符串)。 将[]
放在它之后会产生一种类型的数组。
例如:
const foo = [
'...',
{ compiler: 'abc' /* other properties */ },
'...'
];
将匹配该类型。
示例的TS Playground 链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.