You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function assert(condition:unknown):assertscondition {
99
+
if (!condition) {
100
+
thrownewError('Condition is falsy');
101
+
}
102
+
}
103
+
104
+
assert(false); // Unnecessary; condition is always falsy.
105
+
106
+
const neverNull = {};
107
+
assert(neverNull); // Unnecessary; condition is always truthy.
108
+
109
+
function isString(value:unknown):valueisstring {
110
+
returntypeofvalue==='string';
111
+
}
112
+
113
+
declareconst s:string;
114
+
115
+
// Unnecessary; s is always a string.
116
+
if (isString(s)) {
117
+
}
118
+
119
+
function assertIsString(value:unknown):assertsvalueisstring {
120
+
if (!isString(value)) {
121
+
thrownewError('Value is not a string');
122
+
}
123
+
}
124
+
125
+
assertIsString(s); // Unnecessary; s is always a string.
126
+
```
127
+
128
+
Whether this option makes sense for your project may vary.
129
+
Some projects may intentionally use type predicates to ensure that runtime values do indeed match the types according to TypeScript, especially in test code.
130
+
Often, it makes sense to use eslint-disable comments in these cases, with a comment indicating why the condition should be checked at runtime, despite appearing unnecessary.
131
+
However, in some contexts, it may be more appropriate to keep this option disabled entirely.
0 commit comments