【发布时间】:2021-07-10 08:03:12
【问题描述】:
请考虑以下代码:
const fn = (name: string) => {
return { [name]: "some txt" };
};
const res = fn("books"); // books or any other string
TS 将res 识别为以下类型:
const res: {
[x: string]: string;
}
我想让 TS 知道 res 有一个属性 books
const res: {
books: string;
}
我尝试了很多东西,但似乎没有任何效果。 有可能吗?这是一个已知问题吗?
【问题讨论】:
标签: typescript typescript-typings typescript-generics