Skip to content

Conversation

@Higangssh
Copy link
Contributor

Fixes #11759

PR Checklist

Overview

This PR fixes an issue where the restrict-template-expressions rule incorrectly rejects derived class instances
in template literals when their base class is in the allow list.

Problem

Currently, when a base class is included in the allow option, derived classes extending it are still flagged as
errors, violating the Liskov Substitution Principle where subtypes should be substitutable for their supertypes.

Example:

// Configuration: { allow: [{ from: 'file', name: 'Base' }] }
class Base { }
class Derived extends Base { }
const bar = new Derived();
`${bar}`;  // Error: Invalid type "Derived"

Solution

Implemented recursive base type checking following the pattern established in the no-base-to-string rule:

  1. Added hasBaseTypes() helper function to identify types with base types (Interface or Class)
  2. Added isAllowedTypeOrBase() function that recursively checks if a type or its base types match the allow list
  3. Included cycle detection using a Set to prevent infinite recursion
  4. Updated recursivelyCheckType() to utilize the new base type checking mechanism

Changes

  • packages/eslint-plugin/src/rules/restrict-template-expressions.ts: Added base type checking logic
  • packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts: Added test case for inheritance
    scenario

Allow derived types in template expressions when base types are in allow list

Fixes typescript-eslint#11759
@typescript-eslint
Copy link
Contributor

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.

@netlify
Copy link

netlify bot commented Nov 16, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 80be898
🔍 Latest deploy log https://app.netlify.com/projects/typescript-eslint/deploys/6929e382d0018100097b0a67
😎 Deploy Preview https://deploy-preview-11764--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 81 (🔴 down 17 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link

nx-cloud bot commented Nov 16, 2025

View your CI Pipeline Execution ↗ for commit 80be898

Command Status Duration Result
nx test eslint-plugin --coverage=false ✅ Succeeded 5m 31s View ↗
nx run-many -t lint ✅ Succeeded 3m 17s View ↗
nx run-many -t typecheck ✅ Succeeded 2m 8s View ↗
nx run types:build ✅ Succeeded 1s View ↗
nx run integration-tests:test ✅ Succeeded 6s View ↗
nx test typescript-estree --coverage=false ✅ Succeeded 2s View ↗
nx test eslint-plugin-internal --coverage=false ✅ Succeeded 3s View ↗
nx run generate-configs ✅ Succeeded 5s View ↗
Additional runs (29) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-11-28 18:12:06 UTC

@Higangssh Higangssh changed the title fix(restrict-template-expressions): check base types in allow list fix(eslint-plugin): [restrict-template-expressions] check base types in allow list Nov 16, 2025
@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

❌ Patch coverage is 93.10345% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.48%. Comparing base (16cf0f7) to head (80be898).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/eslint-plugin/src/util/baseTypeUtils.ts 90.90% 4 Missing ⚠️
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              
Flag Coverage Δ
unittest 90.48% <93.10%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...kages/eslint-plugin/src/rules/no-base-to-string.ts 99.01% <100.00%> (-0.07%) ⬇️
...-plugin/src/rules/restrict-template-expressions.ts 100.00% <100.00%> (ø)
packages/eslint-plugin/src/util/baseTypeUtils.ts 90.90% <90.90%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Nov 17, 2025
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a 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!

- Remove unnecessary test comments
- Extract hasBaseTypes to shared util
- Create matchesTypeOrBaseType with matcher pattern
@Higangssh
Copy link
Contributor Author

Thanks for the review! I've addressed all the feedback:

  • Removed unnecessary test comments
  • Extracted hasBaseTypes to shared util
  • Created matchesTypeOrBaseType with matcher pattern

@JoshuaKGoldberg JoshuaKGoldberg self-requested a review November 18, 2025 13:57
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Nov 18, 2025
Copy link
Member

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, C where B is listed
  • A extends B, C where C is listed
  • A extends B, C + B extends D, E where E is listed

etc.

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a 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 JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Nov 18, 2025
@Higangssh
Copy link
Contributor Author

@JoshuaKGoldberg Added tests for multiple interface inheritance. Thanks for the thorough review - really
appreciate you taking the time to guide me through this! Let me know if there's anything else that needs
adjusting

@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Nov 28, 2025
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a 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.

@JoshuaKGoldberg JoshuaKGoldberg merged commit 906cc3c into typescript-eslint:main Nov 28, 2025
64 checks passed
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Dec 2, 2025
| 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.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Dec 4, 2025
| 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.
ch4og pushed a commit to csmplay/mapban that referenced this pull request Dec 4, 2025
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) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@typescript-eslint%2feslint-plugin/8.48.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@typescript-eslint%2feslint-plugin/8.47.0/8.48.1?slim=true)](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) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@typescript-eslint%2fparser/8.48.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@typescript-eslint%2fparser/8.47.0/8.48.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>typescript-eslint/typescript-eslint (@&#8203;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 ([#&#8203;11764](typescript-eslint/typescript-eslint#11764), [#&#8203;11759](typescript-eslint/typescript-eslint#11759))
- **eslint-plugin:** honor ignored base types on generic classes ([#&#8203;11767](typescript-eslint/typescript-eslint#11767))
- **eslint-plugin:** \[consistent-type-exports] check value flag before resolving alias ([#&#8203;11769](typescript-eslint/typescript-eslint#11769))

##### ❤️ Thank You

- Josh Goldberg
- OleksandraKordonets
- SangheeSon [@&#8203;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 ([#&#8203;10744](typescript-eslint/typescript-eslint#10744))

##### 🩹 Fixes

- **typescript-estree:** disallow binding patterns in parameter properties ([#&#8203;11760](typescript-eslint/typescript-eslint#11760))
- **eslint-plugin:** \[consistent-generic-constructors] ignore when constructor is  typed array ([#&#8203;10477](typescript-eslint/typescript-eslint#10477))

##### ❤️ Thank You

- Dima Barabash [@&#8203;dbarabashh](https://github.com/dbarabashh)
- JamesHenry [@&#8203;JamesHenry](https://github.com/JamesHenry)
- Josh Goldberg
- mdm317 [@&#8203;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 (@&#8203;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>
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Dec 4, 2025
| 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.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Dec 5, 2025
| 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.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Dec 6, 2025
| 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.
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.

Bug: [restrict-template-expressions] should check if superclass is ignored

2 participants