gpt4 book ai didi

typescript - "..."[] 在 Typescript 中是什么意思?

转载 作者:行者123 更新时间:2023-12-05 06:53:19 28 4
gpt4 key购买 nike

我正在使用 Typescript配置 webpack。当我配置 module.rules 时,我检查了 types.d.ts 以查看 rules 定义。我看到这个词:

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

我想知道 "..."[] 在 Typescript 中是什么意思

最佳答案

规则集规则 is an object :

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

"..."是一个纯字符串类型。通过将它们括在括号中并用 | 在它们之间交替,您将获得一个匹配其中一个或另一个(对象或字符串)的类型。将 [] 放在它后面会产生一个 array 类型。

例如:

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

将匹配该类型。

TS Playground link的一个例子。

关于typescript - "..."[] 在 Typescript 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65802796/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com