{ [key: string]: boolean; type { [key: string]: boolean;} 意思? [英] What does the type { [key: string]: boolean; } mean?

查看:28
本文介绍了{ [key: string]: boolean; type { [key: string]: boolean;} 意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近遇到这样的事情,一个函数声明:

Run into such thing lately, a function declaration:

static required(control: AbstractControl): {
  [key: string]: boolean;
};

这个返回值是什么?具有任意数量属性的对象,其中每个属性都是布尔值并有一个名称,该名称似乎是一个字符串?我猜这更像是一个打字稿问题,但以防万一有人想知道我在哪里找到的 - 它是 Angular 的 Validators 类.

What is this return value? An object with an arbitrary amount of properties, where each of them is a boolean and has a name, which appears to be a string? It's more of a typescript question I guess, but just in case someone wonders where I found that - it's Angular's Validators class.

推荐答案

这是一个键/值结构.键是 string,值是 boolean.例如:

This is a key/value structure. The key is a string and the value is a boolean. For example:

let map : { [key: string]: boolean} = {};
map["foo"] = true;
map["bar"] = false;
map.foo = true;
map["foobar"] = "foo"; // Throws exception
map[1] = true; // Curiously doesn't throws exception

检查 Typescript Playground 上的这个示例.

可索引类型.

这篇关于{ [key: string]: boolean; type { [key: string]: boolean;} 意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆