Skip to content

feat: port rule @typescript-eslint/no-inferrable-types#449

Merged
fansenze merged 1 commit intomainfrom
feat/port-rule-no_inferrable_types-20260130
Feb 5, 2026
Merged

feat: port rule @typescript-eslint/no-inferrable-types#449
fansenze merged 1 commit intomainfrom
feat/port-rule-no_inferrable_types-20260130

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Jan 30, 2026

Summary

Port the @typescript-eslint/no-inferrable-types rule to rslint.

This rule disallows explicit type declarations for variables or parameters initialized to a number, string, boolean, or other primitives that TypeScript can automatically infer.

Features

  • Supports all inferrable types: bigint, boolean, number, null, RegExp, string, symbol, undefined
  • Handles function calls (BigInt, Boolean, Number, String, Symbol, RegExp)
  • Handles unary expressions (!, +, -)
  • Handles void expressions
  • Options: ignoreParameters, ignoreProperties
  • Properly handles readonly properties (skipped)
  • Properly handles optional properties with ? (skipped)
  • Properly handles definite assignment assertion (!)
  • Properly handles auto-accessor properties with accessor keyword
  • Includes auto-fix to remove redundant type annotations

Infrastructure Changes

  • Added ReportRangeWithFixes to rule context for custom range reporting with fixes

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @fansenze, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates a new TypeScript ESLint rule into the rslint project, focusing on code style and maintainability. The primary goal is to eliminate unnecessary type annotations that TypeScript can infer, thereby making the codebase cleaner and more concise. This enhancement not only adds a valuable linting check but also improves the underlying reporting mechanism to better support automated code corrections.

Highlights

  • New Rule Implementation: The @typescript-eslint/no-inferrable-types rule has been ported to rslint. This rule identifies and disallows explicit type declarations for variables, parameters, and properties when TypeScript can automatically infer their types (e.g., for primitives like number, string, boolean, bigint, null, undefined, symbol, and RegExp).
  • Comprehensive Type Inference Support: The rule supports a wide range of inferrable types and scenarios, including literals (bigint, boolean, number, string, null, RegExp, undefined, symbol), function calls (BigInt, Boolean, Number, String, Symbol, RegExp), unary expressions (!, +, -), and void expressions.
  • Configurable Options: Two options, ignoreParameters and ignoreProperties, are available to customize the rule's behavior, allowing users to selectively ignore explicit type annotations for function parameters or class properties.
  • Advanced Property Handling: The rule correctly handles readonly properties (which are skipped), optional properties with ? (skipped), definite assignment assertions (!), and auto-accessor properties using the accessor keyword.
  • Auto-Fix Capability: The rule includes an auto-fix feature that automatically removes redundant type annotations, improving code conciseness and readability.
  • Infrastructure Enhancement: A new ReportRangeWithFixes function has been added to the rule context, enabling more granular control over reporting diagnostics with associated fixes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request ports the @typescript-eslint/no-inferrable-types rule to rslint. The implementation is comprehensive, covering various inferrable types, expressions, and rule options. The changes include the rule logic, extensive tests, documentation, and necessary adjustments to the linter's rule context. The code is well-structured and follows existing patterns. I have one minor suggestion to improve clarity in the test code.

@fansenze fansenze force-pushed the feat/port-rule-no_inferrable_types-20260130 branch 3 times, most recently from b27f9cb to a0710f8 Compare February 2, 2026 03:22
@fansenze fansenze requested a review from hardfist February 2, 2026 04:39
fansenze added a commit that referenced this pull request Feb 4, 2026
… with JS/official suite

- Add prefer_readonly.md documentation file following PR #449 pattern
- Expand Go test cases from 48 to 158 (76 valid + 82 invalid), fully aligned with JS/official test suite
- Cover all missing patterns: # private fields, optional chaining, non-null assertions, nested property access, method calls, enum/literal/null/Promise type widening, ClassWithName, conditional constructors, etc.
This rule disallows explicit type declarations for variables or parameters
initialized to a number, string, boolean, or other primitives that TypeScript
can automatically infer.

Features:
- Supports all inferrable types: bigint, boolean, number, null, RegExp, string, symbol, undefined
- Handles function calls (BigInt, Boolean, Number, String, Symbol, RegExp)
- Handles unary expressions (!, +, -)
- Handles void expressions
- Options: ignoreParameters, ignoreProperties
- Properly handles readonly properties (skipped)
- Properly handles optional properties with ? (skipped)
- Properly handles definite assignment assertion (!)
- Properly handles auto-accessor properties with accessor keyword
- Includes auto-fix to remove redundant type annotations
- Added ReportRangeWithFixes to rule context for custom range reporting
@fansenze fansenze force-pushed the feat/port-rule-no_inferrable_types-20260130 branch from a0710f8 to 36f6ced Compare February 4, 2026 09:09
@fansenze fansenze merged commit 5805e0e into main Feb 5, 2026
14 checks passed
@fansenze fansenze deleted the feat/port-rule-no_inferrable_types-20260130 branch February 5, 2026 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants