首页 > 解决方案 > 打字稿 | 与端点的接口

问题描述

我需要在 TS 中构建一个接口作为我的一部分dto,它具有以下属性。

interface IFace {
  something.else.more: string;
  something.else.thing: string;
  another.thing.here: number;
}

但我得到一些错误。所以,这就是我所做的:

    interface IFace {
      "something.else.more": string;
      "something.else.thing": string;
      "another.thing.here": number;
    }

我想知道我是否写对了。如果不是,这应该怎么dto写?

标签: javascriptreactjstypescriptobjectecmascript-6

解决方案


JavaScript 中要求任何不包含默认字符集(字母和数字,$以及_)的对象键或变量名都必须被字符串化。

所以是的,这是正确的方法:

interface IFace {
  "something.else.more": string;
  "something.else.thing": string;
  "another.thing.here": number;
}

推荐阅读