Closed
Description
TypeScript Version: 3.8.0-dev.20200208
Search Terms: tag function, tagged template, template string
Code
{
function tag(strings: TemplateStringsArray, ...args: unknown[]): [TemplateStringsArray, unknown[]] {
return [strings, args];
}
// ✅ inferred type: [TemplateStringsArray, unknown[]]
const t = tag`123`;
// console.log(t[2]); // it is correct that this would not compile
}
{
const tag = (strings: TemplateStringsArray, ...args: unknown[]) => [strings, args];
// 🛑 inferred type: (TemplateStringsArray | unknown[])[]
const t = tag`123`;
console.log(t[2]); // should not compile, but it does!
}
Expected behavior:
The console.log(t[2])
statement should produce the following error:
Tuple type '[TemplateStringsArray, unknown[]]' of length '2' has no element at index '2'. ts(2493)
Actual behavior:
The example does compile (but it shouldn't).
Playground Link: here
Related Issues: []
Metadata
Metadata
Assignees
Labels
No labels