8000 Document rationale for allowNumber: false in restrict-template-expressions · Issue #9311 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Document rationale for allowNumber: false in restrict-template-expressions #9311

@danvk

Description

@danvk

Before You File a Proposal Please Confirm You Have Done The Following...

Description

The strict-type-checked configuration sets allowNumber: false for the restrict-template-expressions rule. This prohibits code like the following:

const userId = 123;
const url = `/users/${userId}`;

There is nothing wrong with this code. The official MDN docs on template literals contain code just like it. The typescript-eslint docs for this rule offer no rationale of why interpolating numbers into a string in this way is problematic.

Impacted Configurations

  • strict
  • strict-type-checked

Additional Info

I'm totally bought into all the other options that strict enables for restrict-template-expressions (allowAny, allowArray, allowBoolean, allowNullish, allowNever). These seem potentially problematic since they could result in your inadvertently showing debug code to users. But allowNumber? I'm having trouble seeing any rationale for banning that.

My proposal would be to either change the default setting or add a clear explanation of why interpolating numbers into strings is dangerous.

Possibly related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updatinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0