typescript/consistent-type-assertions Style
What it does
Enforce consistent usage of TypeScript type assertions.
Why is this bad?
Mixing assertion styles (as vs angle-bracket) makes code harder to read and maintain. In some codebases, type assertions are banned in favor of safer alternatives like type annotations or satisfies.
Examples
Examples of incorrect code for this rule (default: assertionStyle: "as"):
const value = <Foo>bar;Examples of correct code for this rule (default: assertionStyle: "as"):
const value = bar as Foo;Examples of incorrect code for this rule with assertionStyle: "angle-bracket":
const value = bar as Foo;Examples of correct code for this rule with assertionStyle: "angle-bracket":
const value = <Foo>bar;Examples of incorrect code for this rule with assertionStyle: "never":
const value = bar as Foo;Examples of correct code for this rule with assertionStyle: "never":
const value: Foo = bar;
const value = bar satisfies Foo;When object/array literal assertions are disallowed, prefer annotations or satisfies:
// incorrect (when `objectLiteralTypeAssertions: "never"`)
const obj = { a: 1 } as Foo;
// correct
const obj: Foo = { a: 1 };
const obj = { a: 1 } satisfies Foo;Configuration
assertionStyle
type: "never"
How to use
To enable this rule using the config file or in the CLI, you can use:
{
"rules": {
"typescript/consistent-type-assertions": "error"
}
}oxlint --deny typescript/consistent-type-assertions