oxlint-plugin-ts-no-assert
v0.1.2
Published
Disallow TypeScript type assertions (as, angle-bracket, non-null !) — ported from eslint-plugin-no-type-assertion to Oxlint's JS plugin API. Also compatible with ESLint flat config.
Maintainers
Readme
oxlint-plugin-ts-no-assert
Disallow TypeScript type assertions (as, angle-bracket <Type>, and non-null !) — ported from eslint-plugin-no-type-assertion to Oxlint's JS plugin API. Also works with ESLint flat config via the bundled eslintCompatPlugin wrapper.
Requirements
- Oxlint
>= 1.0.0(requiresjsPluginssupport) - Node.js
>= 18
Installation
npm add -D oxlint-plugin-ts-no-assert
# or
bun add -d oxlint-plugin-ts-no-assertUsage with Oxlint
Add the plugin to jsPlugins and enable the rule:
// .oxlintrc.json
{
"jsPlugins": ["./node_modules/oxlint-plugin-ts-no-assert/dist/index.js"],
"rules": {
"oxlint-plugin-ts-no-assert/no-type-assertion": "error"
}
}Usage with ESLint
// eslint.config.mjs
import tsNoAssertPlugin from "oxlint-plugin-ts-no-assert/dist/index.js";
export default [
{
plugins: { "no-type-assertion": tsNoAssertPlugin },
rules: tsNoAssertPlugin.configs.recommended.rules,
},
];Rules
no-type-assertion/no-type-assertion
Disallows all three forms of TypeScript type assertion.
Forbidden:
const x = value as MyType; // ❌ Do not use `as` operator for type assertion
const x = <MyType>value; // ❌ Do not use type assertion (angle-bracket)
const x = maybeNull!; // ❌ Do not use non-null assertion operatorAllowed — safe widening that TypeScript itself endorses:
const x = value as unknown; // ✅ widening to unknown is safe
const x = value as const; // ✅ const assertion
const x = <unknown>value; // ✅
const x = <const>value; // ✅Note on angle-bracket syntax: TypeScript disallows
<Type>valuein.tsxfiles because it is syntactically ambiguous with JSX. TheangleBracketAssertiondiagnostic will only appear in plain.tsfiles.
| Rule | Description | Recommended |
|---|---|---|
| no-type-assertion | Disallow as, <Type>, and ! type assertions (except as const / as unknown) | error |
License
MIT
