-
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
Template literal wrong inferred value when multiple placeholders #47048
Comments
This is working as intended, though I'll grant it's a bit odd. The key behavior to understand is that for two immediately adjacent template literal type placeholders we always match a single character from the source to the first placeholder. For example, when matching When resolving the Our matching is not particularly sophisticated, but that is in part by design because we don't want the compiler to be a full regex engine. In general, immediately adjacent placeholders are really only useful for taking strings apart one character at a time. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
template literal wrong infer
π Version & Regression Information
Tested in version 4.1.5, 5.2.3, 4.3.5, 4.4.0, 4.5.2, 4.6.0 nightly, everywhere the same behaviour.
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
d9
is computed asnever
.π Expected behavior
d9
should be computed as'2'
.After debugging a bit
inferFromLiteralPartsToTemplateLiteral
in checker.ts, it seemsp = getSourceText(s).indexOf(delim, p)
searches for2
in a targetTexts being['', 2, '']
yielding a wrong result.It's not clear to me what the actual algorithm should be here as I haven't found any spec or fundamental rules behind inferring template placeholders like above.
The text was updated successfully, but these errors were encountered: