【发布时间】:2021-10-01 17:04:25
【问题描述】:
我想在标记的模板文字函数中从通用参数中获取类型。
但打字稿无法从参数“模板”中读取。它只是读取类型为 TemplateStringsArray。
const tag = <T extends ReadonlyArray<string>>(template: T, ...args: string[]) => {
return {template, args};
};
const a = tag`hello ${'world'}`;
/**
const a: {
template: TemplateStringsArray;
args: string[];
}
*/
有没有办法将template理解为['hello ', '']?
【问题讨论】:
-
你能澄清
value在你的问题中是什么吗? -
有趣的问题。我从来没有以这种方式使用模板文字
标签: typescript