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

后端 未结 1 432
南方客
南方客 2020-12-08 09:48

Run into such thing lately, a function declaration:

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

Wh

相关标签:
1条回答
  • 2020-12-08 10:09

    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
    

    Check this sample on the Typescript Playground.

    Indexable Types.

    0 讨论(0)
提交回复
热议问题