{"record":{"id":"9017f13166b21f57","repo":"oxc-project/oxc","slug":"use-cast-instead-of-as-cast","errorCode":null,"errorMessage":"Use `<{cast}>` instead of `as {cast}`.","messagePattern":"Use `<(.+?)>` instead of `as (.+?)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/consistent_type_assertions.rs","lineNumber":22,"sourceCode":"    AstKind,\n    ast::{Expression, TSType, TSTypeName},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    ast_util::outermost_paren_parent,\n    context::{ContextHost, LintContext},\n    fixer::{RuleFix, RuleFixer},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn use_angle_bracket_diagnostic(cast: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use `<{cast}>` instead of `as {cast}`.\"))\n        .with_help(format!(\"Replace `as {cast}` with `<{cast}>`. For example, change `value as {cast}` to `<{cast}>value`.\"))\n        .with_label(span)\n}\n\nfn use_as_diagnostic(cast: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use `as {cast}` instead of `<{cast}>`.\")).with_label(span)\n}\n\nfn never_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not use any type assertions.\")\n        .with_help(\"Remove the type assertion and use a type annotation instead. For example, change `const x = value as Type` to `const x: Type = value`. Alternatively, use the `satisfies` operator: `const x = value satisfies Type`.\")\n        .with_note(\"Type assertions bypass TypeScript's type checking and can hide type errors. Using type annotations or the `satisfies` operator provides better type safety while still allowing TypeScript to infer types where appropriate.\")\n        .with_label(span)\n}\n\nfn unexpected_object_type_assertion_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Always prefer `const x: T = { ... }`.\")\n        .with_help(\"Replace the object literal type assertion with a type annotation. For example, change `const x = { a: 1 } as Type` to `const x: Type = { a: 1 }`. Alternatively, use `const x = { a: 1 } satisfies Type` if you want TypeScript to infer the exact shape.\")","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/consistent_type_assertions.rs#L4-L40","documentation":"Warning from typescript/consistent-type-assertions via use_angle_bracket_diagnostic() (crates/oxc_linter/src/rules/typescript/consistent_type_assertions.rs:22). With assertionStyle 'angle-bracket', type assertions must use the legacy '<T>value' syntax; it fires on 'value as T' and shows the cast string in both message and help.","triggerScenarios":"oxlint configured with 'consistent-type-assertions': ['error', { assertionStyle: 'angle-bracket' }] and the file contains 'const n = value as string;' or 'foo as unknown as Bar'; the span labels the assertion expression.","commonSituations":"Older TypeScript codebases that standardized on angle-bracket casts before 'as' became dominant; enabling the non-default option on code written with modern style; note angle-bracket assertions are invalid in .tsx files, so the option is rare in React projects.","solutions":["Rewrite 'value as T' as '<T>value' per the rule's fixer and help example","Run 'oxlint --fix' so the rule rewrites all 'as' casts mechanically","If the codebase is .tsx or modern, prefer the default 'as' style and remove the custom assertionStyle"],"exampleFix":"// before\nconst n = value as string;\n\n// after\nconst n = <string>value;","handlingStrategy":"validation","validationCode":"const AS_CAST = /\\bas\\s+\\w+/;\nfor (const line of source.split('\\n')) {\n  if (AS_CAST.test(line)) fail(\"'as' cast used; angle-bracket style required\", line);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use this option in .tsx files — angle-bracket assertions are invalid JSX","Run oxlint --fix to convert casts mechanically","Prefer annotations/satisfies so the option rarely matters"],"tags":["typescript","oxlint","lint","type-assertion","angle-bracket","style"],"backgroundTag":"type-assertion-style","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}