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: crates/oxc_linter/src/rules/typescript/prefer_as_const.rs
+22-7
Original file line number
Diff line number
Diff line change
@@ -23,21 +23,36 @@ pub struct PreferAsConst;
23
23
24
24
declare_oxc_lint!(
25
25
/// ### What it does
26
-
/// Enforce the use of as const over literal type.
26
+
///
27
+
/// Enforce the use of `as const` over literal type.
28
+
///
27
29
/// ### Why is this bad?
28
-
/// There are two common ways to tell TypeScript that a literal value should be interpreted as its literal type (e.g. 2) rather than general primitive type (e.g. number);
29
30
///
30
-
/// as const: telling TypeScript to infer the literal type automatically
31
-
/// as with the literal type: explicitly telling the literal type to TypeScript
31
+
/// There are two common ways to tell TypeScript that a literal value should be interpreted as
32
+
/// its literal type (e.g. `2`) rather than general primitive type (e.g. `number`);
33
+
///
34
+
/// `as const`: telling TypeScript to infer the literal type automatically
35
+
/// `as` with the literal type: explicitly telling the literal type to TypeScript
36
+
///
37
+
/// `as const` is generally preferred, as it doesn't require re-typing the literal value.
38
+
/// This rule reports when an `as` with an explicit literal type can be replaced with an `as const`.
32
39
///
33
-
/// as const is generally preferred, as it doesn't require re-typing the literal value.
34
-
/// This rule reports when an as with an explicit literal type can be replaced with an as const.
0 commit comments