Skip to content

[restrict-template-expressions] Missing handling of intersection type #1797

Closed
@ulrichb

Description

@ulrichb

Repro

{
  "rules": {
    "@typescript-eslint/restrict-template-expressions": "error"
  }
}
type MyString = string & { kind: "MyString" };

const myString = "x" as MyString;

console.log(`myString: ${myString}`); // False positive "Invalid type of template ..."

Expected Result

No error.

Actual Result

"Invalid type of template literal expression"

Additional Info

Real-world example:

import { Term } from "sparqljs";

const someTerm = "x" as Term;

console.log(`someTerm: ${someTerm}`);

See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/638a579eecfa0486115f2440518603f25a8b58b7/types/sparqljs/index.d.ts#L223.

Versions

package version
@typescript-eslint/eslint-plugin 2.25.0
@typescript-eslint/parser 2.25.0

Proposed solution

Don't emit an error if any item of the intersection type is "allowed" in respect to the options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomershas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions