Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I havesearched for related issues and found none that match my proposal.
- I have searched thecurrent rule list and found no rules that match my proposal.
- I haveread the FAQ and my problem is not listed.
My proposal is suitable for this project
- My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
- My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Description
I'd likeString(something)
,something.toString()
, and perhapssomething as string
to show an error if something is astring
already, but to be allowed if it's astring | number
or even astring | number | undefined
. This is similar to the proposal at#6385 but it appears there're some issues with doing this with numbers that I don't think applies to strings.
In my case, I would like to do this because I am working with a library that exports astring | number | undefined
, but I believe their type is incorrect, and I would like to essentially be notified that I can remove my casts if the type changes and becomes astring
instead, and I believe similar use cases would not be exceeding rare, where one might be able to catch useless casts after updating one type somewhere, whether in a library or in their own type definitions. My feeling is that if this were turned on it would trigger errors in more than a couple of codebases. In reference to the similar issue for numbers, I do support the implementation of that as well for similar reasons.
Fail Cases
letreplace='me';replace=String(replace)
Pass Cases
letreplace:string|number='me';replace=String(replace)
Additional Info
This is also similar to eslint'shttps://eslint.org/docs/latest/rules/no-extra-boolean-cast, which I'm actually not sure how they achieve without typescript, but that rule makes a lot of sense to me as well.