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 literals are unsupported for nested calls #341
Comments
Just came to say this, I can't do the following, for example:
Outputs as Any solution to the above? |
@i-break-codes The OP is an entirely different issue. What you want is specifically not supported. You'll need to write a template literal wrapper, as template literals are not as simple as a function call. @ExE-Boss's issue is that the typescript definitions allow you to use |
So what needs to be done here is to change the TypeScript types to not allow the template literal on Chalk sub-properties like |
Correct. Only on instances of |
@issuehunt has funded $40.00 to this issue.
|
I feel like fixing the TypeScript definition is not worth 40 bucks. I’d much rather prefer if this was implemented so that: chalk.red`foo ${bar}`; and chalk`{red foo ${bar}}`; were equivalent. That way, bugs like mdn/browser-compat-data#4480 could be more easily avoided. |
I agree, would be better to actually support that. |
Supporting that is going to introduce more branching to the individual styles in order to check to see if the passed arguments match that of a tagged template invocation (since there's no quick way to check). I really wish the folks at the tc39 thought about this; the design is horrendous. I really wish they had created a specified function property that was invoked instead, so you'd have function foo() {
console.log('regular invocation');
}
foo.tag = function() {
console.log('tagged invocation');
}
foo(); // regular invocation
foo`hello`; // tagged invocation But alas, we have to check the existence of random properties and arrays which take the form of if statements. Supporting this will ultimately hurt performance by introducing branching. Is that what we want? |
Let's fix the TypeScript definition for now, and we can look into allowing it later on, as long as the performance is not impacted (which seems hard). |
modified: test/template-literal.js
Maybe the performance tradeoff will be worth it? Are there perf tests to inform a decision? |
I proposed a solution in #392 . The behavior of Only when the functions is called as a template literal, the template substitution will be evaluated: Note the difference between |
You cannot possibly assert this. There is no special function invocation for template literals aside from different argument types, so you'd have to do a branch (an Branches are very much overhead, and can be quite detrimental in tight loops if gone unchecked. |
@sindresorhus has rewarded $36.00 to @toonijn. See it on IssueHunt
|
The following is unsupported despite it being allowed by the type system:
Produces:
Instead of:
IssueHunt Summary
toonijn has been rewarded.
Backers (Total: $40.00)
Submitted pull Requests
Tips
The text was updated successfully, but these errors were encountered: