Closed
Description
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 option ignoreNullishCheck
to disable higlighting them.
Reference: https://typescript-eslint.io/rules/no-misused-promises/
Incorrect code
const signal = signal(0);
const otherSignal = signal(0);
if (signal) {
// Do something
}
if (signal === otherSignal) {
// Do something
}
if (signal > otherSignal) {
// Do something
}
if (
767E
signal < otherSignal) {
// Do something
}
const val = signal ? 123 : 456;
while (signal) {
// Do something
}
@if (signal) {
something
}
@if (signal === otherSignal) {
something
}
@if (signal > otherSignal) {
something
}
@if (signal < otherSignal) {
something
}
@switch (signal) {
something
}
{{ signal }}
Correct code
const signal = signal(0);
const otherSignal = signal(0);
if (signal()) {
// Do something
}
if (signal() === otherSignal()) {
// Do something
}
if (signal() > otherSignal()) {
// Do something
}
if (signal() < otherSignal()) {
// Do something
}
const val = signal() ? 123 : 456;
while (signal()) {
// Do something
}
@if (signal()) {
something
}
@if (signal() === otherSignal()) {
something
}
@if (signal() > otherSignal()) {
something
}
@if (signal() < otherSignal()) {
something
}
@switch (signal()) {
something
}
{{ signal() }}