Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@joshkel

Description

@joshkel

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.2.2&fileType=.tsx&code=MYGwhgzhAEBCkFNoG9oF8BQpIwCIICcBLANwQBNoEAPAFwQDtyZ4IlVNgB7BiW6AGZcu0ALzQGCAO5xEACgCUAbiw8%2B0AEZgCYidOj5iZcopUADACTIhXNFa0E0ZpUA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6aFfKsu-RAW2LwAhn3oAPYh2TJKAeyaoMAbXDYciaNDnRIAGjXrgUYfHhyA7ujDLIAIWHJEkALoBfQ2BdqPboA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

class Base { }
class Derived extends Base { }
const foo = new Base();
const bar = new Derived();
`${foo}${bar}`;

ESLint Config

{
  "rules": {
    "@typescript-eslint/restrict-template-expressions": [
      "error",
      { "allow": ["Base"]}
    ]
  }
}

tsconfig

{
  "rules": {
    "@typescript-eslint/restrict-template-expressions": [
      "error",
      { "allow": ["Base"]}
    ]
  }
}

Expected Result

No warnings - if Base is allowed and every instance of Derived is also a Base, then Derived should be allowed. (This would also be consistent with the no-base-to-string rule - see #11520.)

Actual Result

Invalid type "Derived" of template literal expression. 5:10 - 5:13

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions