[no-misused-signals] restrict incorrect usage of signals - proposal #2302
MillerSvt
started this conversation in
New Rule Proposals
Replies: 3 comments
-
This seems to be a duplicate of #1753 and should probably be merged into a single issue. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Since signals are functions, this is also valid typescript code, but will never run, as const mySignal = signal(['hello', 'world']);
if (mySignal.length > 0) {
...
} Just happened to me recently when converting a component to use signals, and I'm recently sure that is not that uncommon |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks folks, it makes sense to me and I'll happily accept a PR for this rule |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description of the proposal
This rule forbids providing Signals to logical locations such as if statements in places where the TypeScript compiler allows them but they are not handled properly. It could be about using signals in a nullish check or comparing them using operators like
===
,==
,>
,<
,>=
, or<=
. These situations can often arise due to a missing call or just a misunderstanding of the way signals are handled.In some rare cases
===
or==
operators can be valid. So need to add optionignoreNullishCheck
to disable higlighting them.Reference: https://typescript-eslint.io/rules/no-misused-promises/
Incorrect code
Correct code
Beta Was this translation helpful? Give feedback.
All reactions