如何在Typescript中为Map的类型别名定义索引签名?

时间:2019-02-09 17:46:39

标签: javascript typescript typescript2.0 typing

如果我为dataGridView1.AutoSize = true; 定义了这样的类型:

using System.Drawing;
using System.Windows.Forms;
public class MyPanel : Panel
{
    protected override Point ScrollToControl(Control activeControl)
    {
        return this.AutoScrollPosition;
    }
}

如何添加索引签名,以便在创建后设置键值?我已经能够使用定义不同属性的类型来做这些事情,例如:

Map

但是在上述情况下,我找不到解决方法。

1 个答案:

答案 0 :(得分:1)

我认为您正在寻找这样的东西:

type Obj = MyCustomObj<string, number>;
type CustomObj = MyCustomObj<string, number, { key: boolean }>;

您可以这样使用它:

ERROR: SSL error: HTTPSConnectionPool(host='host', port=2376): Max retries exceeded with url: /v1.25/containers/json?all=1&limit=-1&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dappname%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D&trunc_cmd=0&size=0 (Caused by SSLError(SSLError(1, u'[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:726)'),))

Playground