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
Copy file name to clipboardExpand all lines: docs/src/rules/no-unused-expressions.md
+61
Original file line number
Diff line number
Diff line change
@@ -276,3 +276,64 @@ const myFragment = <></>;
276
276
```
277
277
278
278
:::
279
+
280
+
### TypeScript Support
281
+
282
+
This rule supports TypeScript-specific expressions and follows these guidelines:
283
+
284
+
1. Directives (like `'use strict'`) are allowed in module and namespace declarations
285
+
2. Type-related expressions are treated as unused if their wrapped value expressions are unused:
286
+
* Type assertions (`x as number`, `<number>x`)
287
+
* Non-null assertions (`x!`)
288
+
* Type instantiations (`Set<number>`)
289
+
290
+
**Note**: Although type expressions never have runtime side effects (e.g., `x!` is equivalent to `x` at runtime), they can be used to assert types for testing purposes.
291
+
292
+
Examples of **correct** code for this rule when using TypeScript:
293
+
294
+
::: correct
295
+
296
+
```ts
297
+
/* eslint no-unused-expressions: "error" */
298
+
299
+
// Type expressions wrapping function calls are allowed
300
+
function getSet() {
301
+
returnSet;
302
+
}
303
+
getSet()<number>;
304
+
getSet() asSet<unknown>;
305
+
getSet()!;
306
+
307
+
// Directives in modules and namespaces
308
+
moduleFoo {
309
+
'use strict';
310
+
'hello world';
311
+
}
312
+
313
+
namespaceBar {
314
+
'use strict';
315
+
exportclassBaz {}
316
+
}
317
+
```
318
+
319
+
:::
320
+
321
+
Examples of **incorrect** code for this rule when using TypeScript:
0 commit comments