Skip to content

Add no-restricted-syntax rule for union type assertions (no as)#57

Merged
noamokman merged 3 commits into
osskit:mainfrom
omerlh:add-no-union-type-assertion-rule
Mar 1, 2026
Merged

Add no-restricted-syntax rule for union type assertions (no as)#57
noamokman merged 3 commits into
osskit:mainfrom
omerlh:add-no-union-type-assertion-rule

Conversation

@omerlh

@omerlh omerlh commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Adds a no-restricted-syntax rule that disallows TypeScript union type assertions (value as A | B). The rule suggests using type guards, narrowing, or typed constructors instead. Non-union assertions (e.g. as const) remain allowed.

Also fixes the pre-existing lint failure in fixtures/ts.ts where @typescript-eslint/unified-signatures threw on that file; the rule is disabled for that fixture in the sample configs.

Review: @noam — could you review when you have a moment?

Made with Cursor

Comment thread sampleConfigs/test.config.js Outdated
{
files: ['fixtures/ts.ts'],
rules: {
'@typescript-eslint/unified-signatures': 'off',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why turn this off?

@omerlh

omerlh commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

@noamokman Re your question on turning off unified-signatures: we had to disable it for fixtures/ts.ts because the rule was throwing (typeParameters.params is not iterable) when linting that file—a bug in the rule with that fixture’s AST. After upgrading to the latest deps, the crash is gone, so I removed that workaround in the latest commit. The rule now runs on the fixture without issues.

@noamokman
noamokman enabled auto-merge (squash) March 1, 2026 07:27
@noamokman
noamokman merged commit 62942e9 into osskit:main Mar 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants