-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(eslint-plugin): [restrict-template-expressions] check base types in allow list #11764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(eslint-plugin): [restrict-template-expressions] check base types in allow list #11764
Conversation
Allow derived types in template expressions when base types are in allow list Fixes typescript-eslint#11759
|
Thanks for the PR, @Higangssh! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 80be898
☁️ Nx Cloud last updated this comment at |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11764 +/- ##
==========================================
- Coverage 90.49% 90.48% -0.01%
==========================================
Files 522 523 +1
Lines 53367 53393 +26
Branches 8918 8919 +1
==========================================
+ Hits 48293 48315 +22
- Misses 5059 5063 +4
Partials 15 15
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! ✨
Just a few cleanup/refactor requests, nothing on the core logic. Thanks for getting this started!
packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/restrict-template-expressions.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/restrict-template-expressions.ts
Outdated
Show resolved
Hide resolved
…te-expressions-base-types
- Remove unnecessary test comments - Extract hasBaseTypes to shared util - Create matchesTypeOrBaseType with matcher pattern
|
Thanks for the review! I've addressed all the feedback:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Testing] Oh, sory, I just realized - this is missing test coverage for extending multiple classes.
A extends B, CwhereBis listedA extends B, CwhereCis listedA extends B, C+B extends D, EwhereEis listed
etc.
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, a bit more testing please
|
@JoshuaKGoldberg Added tests for multiple interface inheritance. Thanks for the thorough review - really |
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 thanks! Very thorough, nicely done.
| datasource | package | from | to | | ---------- | -------------------------------- | ------ | ------ | | npm | @typescript-eslint/eslint-plugin | 8.48.0 | 8.48.1 | | npm | @typescript-eslint/parser | 8.48.0 | 8.48.1 | ## [v8.48.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8481-2025-12-02) ##### 🩹 Fixes - **eslint-plugin:** \[restrict-template-expressions] check base types in allow list ([#11764](typescript-eslint/typescript-eslint#11764), [#11759](typescript-eslint/typescript-eslint#11759)) - **eslint-plugin:** honor ignored base types on generic classes ([#11767](typescript-eslint/typescript-eslint#11767)) - **eslint-plugin:** \[consistent-type-exports] check value flag before resolving alias ([#11769](typescript-eslint/typescript-eslint#11769)) ##### ❤️ Thank You - Josh Goldberg - OleksandraKordonets - SangheeSon [@Higangssh](https://github.com/Higangssh) - tao You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website.
| datasource | package | from | to | | ---------- | -------------------------------- | ------ | ------ | | npm | @typescript-eslint/eslint-plugin | 8.48.0 | 8.48.1 | | npm | @typescript-eslint/parser | 8.48.0 | 8.48.1 | ## [v8.48.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8481-2025-12-02) ##### 🩹 Fixes - **eslint-plugin:** \[restrict-template-expressions] check base types in allow list ([#11764](typescript-eslint/typescript-eslint#11764), [#11759](typescript-eslint/typescript-eslint#11759)) - **eslint-plugin:** honor ignored base types on generic classes ([#11767](typescript-eslint/typescript-eslint#11767)) - **eslint-plugin:** \[consistent-type-exports] check value flag before resolving alias ([#11769](typescript-eslint/typescript-eslint#11769)) ##### ❤️ Thank You - Josh Goldberg - OleksandraKordonets - SangheeSon [@Higangssh](https://github.com/Higangssh) - tao You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website.
This PR contains the following updates: | Package | Change | Age | Confidence | |---|---|---|---| | [@typescript-eslint/eslint-plugin](https://typescript-eslint.io/packages/eslint-plugin) ([source](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin)) | [`8.47.0` -> `8.48.1`](https://renovatebot.com/diffs/npm/@typescript-eslint%2feslint-plugin/8.47.0/8.48.1) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | [@typescript-eslint/parser](https://typescript-eslint.io/packages/parser) ([source](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser)) | [`8.47.0` -> `8.48.1`](https://renovatebot.com/diffs/npm/@typescript-eslint%2fparser/8.47.0/8.48.1) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>typescript-eslint/typescript-eslint (@​typescript-eslint/eslint-plugin)</summary> ### [`v8.48.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8481-2025-12-02) [Compare Source](typescript-eslint/typescript-eslint@v8.48.0...v8.48.1) ##### 🩹 Fixes - **eslint-plugin:** \[restrict-template-expressions] check base types in allow list ([#​11764](typescript-eslint/typescript-eslint#11764), [#​11759](typescript-eslint/typescript-eslint#11759)) - **eslint-plugin:** honor ignored base types on generic classes ([#​11767](typescript-eslint/typescript-eslint#11767)) - **eslint-plugin:** \[consistent-type-exports] check value flag before resolving alias ([#​11769](typescript-eslint/typescript-eslint#11769)) ##### ❤️ Thank You - Josh Goldberg - OleksandraKordonets - SangheeSon [@​Higangssh](https://github.com/Higangssh) - tao You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website. ### [`v8.48.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8480-2025-11-24) [Compare Source](typescript-eslint/typescript-eslint@v8.47.0...v8.48.0) ##### 🚀 Features - **eslint-plugin:** \[no-redundant-type-constituents] use assignability checking for redundancy checks ([#​10744](typescript-eslint/typescript-eslint#10744)) ##### 🩹 Fixes - **typescript-estree:** disallow binding patterns in parameter properties ([#​11760](typescript-eslint/typescript-eslint#11760)) - **eslint-plugin:** \[consistent-generic-constructors] ignore when constructor is typed array ([#​10477](typescript-eslint/typescript-eslint#10477)) ##### ❤️ Thank You - Dima Barabash [@​dbarabashh](https://github.com/dbarabashh) - JamesHenry [@​JamesHenry](https://github.com/JamesHenry) - Josh Goldberg - mdm317 [@​gen-ip-1](https://github.com/gen-ip-1) You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website. </details> <details> <summary>typescript-eslint/typescript-eslint (@​typescript-eslint/parser)</summary> ### [`v8.48.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#8481-2025-12-02) [Compare Source](typescript-eslint/typescript-eslint@v8.48.0...v8.48.1) This was a version bump only for parser to align it with other projects, there were no code changes. You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website. ### [`v8.48.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#8480-2025-11-24) [Compare Source](typescript-eslint/typescript-eslint@v8.47.0...v8.48.0) This was a version bump only for parser to align it with other projects, there were no code changes. You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website. </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4xNC4yIiwidXBkYXRlZEluVmVyIjoiNDIuMTQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Reviewed-on: https://git.csmpro.ru/csmpro/mapban/pulls/57 Co-authored-by: Renovate Bot <renovate@csmpro.ru> Co-committed-by: Renovate Bot <renovate@csmpro.ru>
| datasource | package | from | to | | ---------- | -------------------------------- | ------ | ------ | | npm | @typescript-eslint/eslint-plugin | 8.48.0 | 8.48.1 | | npm | @typescript-eslint/parser | 8.48.0 | 8.48.1 | ## [v8.48.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8481-2025-12-02) ##### 🩹 Fixes - **eslint-plugin:** \[restrict-template-expressions] check base types in allow list ([#11764](typescript-eslint/typescript-eslint#11764), [#11759](typescript-eslint/typescript-eslint#11759)) - **eslint-plugin:** honor ignored base types on generic classes ([#11767](typescript-eslint/typescript-eslint#11767)) - **eslint-plugin:** \[consistent-type-exports] check value flag before resolving alias ([#11769](typescript-eslint/typescript-eslint#11769)) ##### ❤️ Thank You - Josh Goldberg - OleksandraKordonets - SangheeSon [@Higangssh](https://github.com/Higangssh) - tao You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website.
| datasource | package | from | to | | ---------- | -------------------------------- | ------ | ------ | | npm | @typescript-eslint/eslint-plugin | 8.48.0 | 8.48.1 | | npm | @typescript-eslint/parser | 8.48.0 | 8.48.1 | ## [v8.48.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8481-2025-12-02) ##### 🩹 Fixes - **eslint-plugin:** \[restrict-template-expressions] check base types in allow list ([#11764](typescript-eslint/typescript-eslint#11764), [#11759](typescript-eslint/typescript-eslint#11759)) - **eslint-plugin:** honor ignored base types on generic classes ([#11767](typescript-eslint/typescript-eslint#11767)) - **eslint-plugin:** \[consistent-type-exports] check value flag before resolving alias ([#11769](typescript-eslint/typescript-eslint#11769)) ##### ❤️ Thank You - Josh Goldberg - OleksandraKordonets - SangheeSon [@Higangssh](https://github.com/Higangssh) - tao You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website.
| datasource | package | from | to | | ---------- | -------------------------------- | ------ | ------ | | npm | @typescript-eslint/eslint-plugin | 8.48.0 | 8.48.1 | | npm | @typescript-eslint/parser | 8.48.0 | 8.48.1 | ## [v8.48.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8481-2025-12-02) ##### 🩹 Fixes - **eslint-plugin:** \[restrict-template-expressions] check base types in allow list ([#11764](typescript-eslint/typescript-eslint#11764), [#11759](typescript-eslint/typescript-eslint#11759)) - **eslint-plugin:** honor ignored base types on generic classes ([#11767](typescript-eslint/typescript-eslint#11767)) - **eslint-plugin:** \[consistent-type-exports] check value flag before resolving alias ([#11769](typescript-eslint/typescript-eslint#11769)) ##### ❤️ Thank You - Josh Goldberg - OleksandraKordonets - SangheeSon [@Higangssh](https://github.com/Higangssh) - tao You can read about our [versioning strategy](https://typescript-eslint.io/users/versioning) and [releases](https://typescript-eslint.io/users/releases) on our website.

Fixes #11759
PR Checklist
3Aopen+is%3Aissue+label%3A%22accepting+prs%22)
Overview
This PR fixes an issue where the
restrict-template-expressionsrule incorrectly rejects derived class instancesin template literals when their base class is in the allow list.
Problem
Currently, when a base class is included in the
allowoption, derived classes extending it are still flagged aserrors, violating the Liskov Substitution Principle where subtypes should be substitutable for their supertypes.
Example:
Solution
Implemented recursive base type checking following the pattern established in the no-base-to-string rule:
Changes
scenario