Can you help me with this code snippet?
const fn = (name: string) => {
return { [name]: "some txt" };
};
const res = fn("books"); // books or any other string
The type of res
recognized by TS is:
const res: {
[x: string]: string;
}
I want to specify that res
should have a property called books
const res: {
books: string;
}
I've tried different approaches but nothing seems to be working. Is it even possible to achieve this? Or is it a known limitation in TypeScript?