Skip to content

Bug: [restrict-template-expressions] Doesn't treat String class instances as strings #11697

@Finesse

Description

@Finesse

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.9.2&fileType=.tsx&code=MYewdgzgLgBNBOBLMBzAwgGwIYQgSUiizGAFMYBeGMUgdxgGUolUAKAcgDMQR2BKANwAoIcGy4YaAK7QQAWyYsUMUgA8opMABMIjZsmUBvAL4jQhOPtQBRdZq2l4BaMTKVqdSTKjzFBjty8fGbgECAYpAB0GCAorAAGaDjkAIwAXDAAJIYIBpg4%2BISupMbxgqKh4VExcYnJMABMGdm5Nnbajs5EJCVlwkIA9AMwAIJaWgYwAEQAAlAAngAOpBDASItQALQrGMhQA-Ar%2BsBbGnKL2BrbqouHuIihUxkA2lOO8CDwUwA0MIbTWAwMVoTxgz3%2BU04HzkoKmuwARj9pmAsHJSKDXn5UFMALowYx4gmDYY%2BFQQXZgZjAGCcRCqFYwYD1FIweFSWBgECwJkQcgNSJCIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6aFfKsu-RAW2LwAhn3oAPYh2TJKAeyaoMkRNGhzokcGAC%2BIHUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

`${new String('')}`

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/restrict-template-expressions": "error"
  },
};

tsconfig

{
  "compilerOptions": {}
}

Expected Result

The rule allows String class instances and instances of classes extending String in template expressions. Or at least has an option to allow that.

Actual Result

ESLint produces an error: Invalid type "String" of template literal expression.

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