Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 流量类型:方括号之间的字段_Javascript_Typescript_Types_Flowtype - Fatal编程技术网

Javascript 流量类型:方括号之间的字段

Javascript 流量类型:方括号之间的字段,javascript,typescript,types,flowtype,Javascript,Typescript,Types,Flowtype,在流类型中: export type GroupType = { options: OptionsType, [string]: any, }; 什么是[string]:any的意思? import type { GroupType } from './types'; const formatGroupLabel = (group: GroupType): string => group.label; 编辑: 谢谢你的回复 我必须如何理解这段代码? import type {

在流类型中:

export type GroupType = {
  options: OptionsType,
  [string]: any,
};
什么是
[string]:any
的意思?

import type { GroupType } from './types';
const formatGroupLabel = (group: GroupType): string => group.label;
编辑:

谢谢你的回复

我必须如何理解这段代码?

import type { GroupType } from './types';
const formatGroupLabel = (group: GroupType): string => group.label;

对于我来说,
formatGroupLabel
是一个函数,它将
group
作为参数,并返回
group.label
。但是我不明白为什么在
(group:GroupType)
前面有
:string
。可能与我的第一个问题没有链接。

这是一个索引属性,这意味着如果您试图获取一个键为
字符串的属性,则该值将是
any
类型

这样使用它以避免混淆是很常见的(但两种方法都是有效的):

因此,您可以将其用于以下对象:

/**@type{GroupType}*/
变量类型={
选项:{},
答:1,,
b:“福”,
c:函数fooBar(){}
};
console.log(类型为[“a”]);
console.log(类型为[“b”]);

console.log(类型为[“c”])更新了我的答案,尽管我认为这应该是一个不同的问题。