What does "..."[] mean in Typescript?

Viewed 109

I am using Typescript to configure webpack. When I configure the module.rules, I checked the types.d.ts to see rules definition. And I see this words:

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

And I want to know what does "..."[] mean in Typescript

1 Answers

RuleSetRule is an 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). 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.

Related