typescript - 如何在打字稿中重建文字字符串键
问题描述
我们知道我们可以用来keyof
从对象中提取密钥。
const a = { a1: 1, b2: 1, c3: 1 };
type AI = {
[key in keyof typeof a]: boolean;
}
在这里我们得到了新类型
type AI = {
a1: boolean;
b2: boolean;
c3: boolean;
}
但是如何重命名密钥,有人知道吗?</p>
type AI = {
[key in ( 'prefix_' + keyof typeof a)]: boolean;// wrong
}
// here I want to get type
type AI = {
prefix_a1: boolean;
prefix_b2: boolean;
prefix_c3: boolean;
}
解决方案
推荐阅读
- javascript - 预注册 Cognito 触发器
- bitbucket - BitBucket API 获取存储库管理员
- android - 如何从两种不同的方式(房间、用户)处理 Android LiveData 更改?
- java - 如何检查给定的firebase引用是否不包含任何值或为空
- tomcat - 如何在 tomcat 7 中获取映射到 index.html 的基本 url?
- sql-server - 如何抑制sql查询输出并仅显示行数
- vim - 如何格式化某些行中包含空列的表格?
- excel - 查找与值关联的最后一个非空白单元格
- powerbi - Power Bi,按月比较文本列
- angular - 每日更新的网站,推荐使用 Angular 吗?