-
Notifications
You must be signed in to change notification settings - Fork 889
Rule suggestion: strict-string-expressions (no implicit function to string) #4512
Comments
@ColCh this is a really interesting idea, thanks! I've definitely felt the exact pain you've described, and would like to see a rule helping. On the other hand, the following should be allowed, right? class CanBeStringified {
toString() {
return "This works fine...";
}
}
const stringified = new CanBeStringified();
alert(`Result: ${stringified}`); So is it that this rule should ban objects that whose Let's discuss a bit to nail down how this should behave. |
I was just looking for a rule for this. microsoft/vscode#68966
Yes, I would want something specifically for functions and methods, (or type unions that could represent functions). I think that's the mistake that I'm most likely to make. It could also be useful for arrays, objects that don't have a non-default toString method, |
Since TSLint migration to ESLint (medium post) and presence of this rule in eslint (no-implicit-coercion), I think it would be nice just to close this issue :) What do you think? |
@ColCh there are still very many users on TSLint who rely on the features and/or rules that haven't yet been ported over to ESLint. Let's keep this issue open for the time being.
|
Let's call this |
@JoshuaKGoldberg #4512 (comment) That makes things complicated :) What about this example?
I think, that in this case
hm, may be all things would require explicit like
and pass only for strings
|
@ColCh yes, that makes sense & I agree. The simplest theology here makes sense: complex objects such as class instances and functions should have explicit |
Note: per #4534, this issue will be closed in less than a month if no PR is sent to add the rule. If you really need the rule, custom rules are always an option and can be maintained outside this repo! |
Rule Suggestion
There is some common pattern
But it's easy to miss brackets around function and this would be not an error
What does your suggested rule do?
If it's
on
, require explicittoString
orString
call aroundfunction
Like this
Additional context
What about spreading this rule for other data types?
I think this is frustrating sometimes:
What do you think?
The text was updated successfully, but these errors were encountered: