-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Computed string literal can't be used as generic argument #58494
Comments
Thatβs bizarre - itβs inferring |
The OP's repro is quite bizarre π±
That was meant to be my guess but - obviously - you are already one step ahead :D |
My PR is definitely related but it's not the whole story. I'll bisect the other bit more later but I wouldn't be surprised if that would point to some other PR of mine π The OP's case changed between 5.1 and 5.2. #53907 was included as part of 5.1 already and it accidentally changed @jcalz's examples and things like this: const a = "1";
const b = a + " 2";
enum E {
A = b, // "1 2", wat
} |
The issue with #53907 is that it only performs constant evaluation when the criteria for creating a template literal type are not satisfied (i.e. constant evaluation only occurs in situations where the type would otherwise have been |
Another example of the strangeness: const a = '1'; // "1"
const b = a + ' 2'; // string
const c = `${b} 3`; // "1 2 3"
const d = `${b} 3` as const; // `${string} 3` It definitely doesn't make sense for Apart from that, it's a bit odd that |
Yeah, that threw me for a loop too. I know TS has a concept of "widening" types where a literal type can be widened to its base primitive type, but this is the first time I've ever seen a "narrowing" type! |
π Search Terms
"string literal is not assignable to parameter of type", "generic string literal argument"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABMMAeAKgPgBQEMBOA5gFyLoCUp6iA3gFCKOL4CmUI+SBhA3HQL506EBAGcoiXIgC8iAOQBGOXxFhxiAEYzJiANTzEAJmVCU2AAYASGhv6IAzOfI8gA
π» Code
π Actual behavior
π Expected behavior
No errors are expected
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: