简体   繁体   English

Typescript 中的“...”[] 是什么意思?

[英]What does “…”[] mean in Typescript?

I am using Typescript to configure webpack.我正在使用Typescript来配置 webpack。 When I configure the module.rules , I checked the types.d.ts to see rules definition.当我配置module.rules时,我检查了types.d.ts以查看rules定义。 And I see this words:我看到这句话:

/**
 * An array of rules applied for modules.
 */
rules?: (RuleSetRule | "...")[];

And I want to know what does "..."[] mean in Typescript我想知道 Typescript 中的"..."[]是什么意思

RuleSetRuleis an object : RuleSetRule是一个 object

declare interface RuleSetRule {
    /**
     * Match the child compiler name.
     */
    compiler?:
        | string
        | RegExp
        | {
   ... lots of lines

And "..." is a plain string type."..."是纯字符串类型。 By enclosing these in parentheses and alternating between them with |通过将它们括在括号中并在它们之间交替使用| , you get a type that matches either one or the other (either the object or the string). ,你会得到一个匹配一个或另一个的类型(object 或字符串)。 Putting [] after it results in a type of an array of those.[]放在它之后会产生一种类型的数组

For example:例如:

const foo = [
  '...',
  { compiler: 'abc' /* other properties */ },
  '...'
];

would match that type.将匹配该类型。

TS Playground link of an example.示例的TS Playground 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM