javascript - 打字稿 | 与端点的接口
问题描述
我需要在 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
写?
解决方案
JavaScript 中要求任何不包含默认字符集(字母和数字,$
以及_
)的对象键或变量名都必须被字符串化。
所以是的,这是正确的方法:
interface IFace {
"something.else.more": string;
"something.else.thing": string;
"another.thing.here": number;
}
推荐阅读
- encryption - 我可以编写代码来加密/解密 TLSv1.2 数据包吗?
- javascript - 故事书转换为 CSF
- google-apps-script - 有没有办法让指定用户的谷歌文档处于建议模式,同时仍然允许运行添加的脚本?
- c++ - 指针问题:从不兼容的类型“int”分配给“int *”
- hl7-fhir - 将原始 txt 数据转换为 JSON 格式的 FHIR 资源
- sql - 查询不同数据库中同名的多个表
- python - Python 网页抓取动态内容
- ruby-on-rails - Rails Puma:--no-dev-caching 不起作用
- post - 发布请求总是在 JMeter 中返回错误
- django - 在 Django 中,on_delete 是用 Python 实现的,还是使用 DB 触发器实现的,用于 PostgreSQL 数据库?