Computed string literal can't be used as generic argument
DimaIT opened this issue ยท comments
Dzmitry Tolpekin commented
๐ Search Terms
"string literal is not assignable to parameter of type", "generic string literal argument"
๐ Version & Regression Information
- This changed between versions 5.1.6 and 5.2.2
โฏ Playground Link
๐ป Code
function fn<T>(arg: T): T {
return arg;
}
const a = '1';
const b = a + ' 2';
fn(`${b} 3`);
๐ Actual behavior
Argument of type '`${string} 3`' is not assignable to parameter of type '"1 2 3"'.
๐ Expected behavior
No errors are expected
Additional information about the issue
No response
Bruce Pascoe commented
Thatโs bizarre - itโs inferring T = "1 2 3"
from the argument, but then deciding the same argument isnโt assignable to the type it just inferred.
Joe Calzaretta commented
Mateusz Burzyลski commented
The OP's repro is quite bizarre ๐ฑ
Did #53907 do this somehow?
That was meant to be my guess but - obviously - you are already one step ahead :D