Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enhancement: [no-type-alias] allowTemplateLiterals #5095

Closed as not planned
Closed as not planned
Labels
enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on
@burtek

Description

@burtek

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

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-type-alias

Description

Template Literals is a powerfull TypeScript feature, allowing to specify exact form a string may take. Using template literals allows to force specific input form, eg:

typeJiraTicketNumber= `${'PROJ01'|'PROJ02'}-${number}`typeChatCommand= `/${keyoftypeofcommands}`typeFilterField= `${'include'|'exclude'}: ${string}`typeLang='en'|'de'|'es'typePage='home'|'blog'|'store'typeURLSlug= `/${Lang}/${Page}`

but also allowing to mapping keys to another type (see examples in link above).

There might be (and in my case actually is) a case, where type aliasing is generally not allowed (apart from unions / intersections), with template literal being exception, as it's recommended to share the single definition of this type rather than have to use the template literal type in many different places, as that may lead to issues when the form of the template literal type changes.

I'd love to suggest adding newallowTemplateLiterals option that would handle such case. Template Literals are a new, unique form of typescript type and while there is an option to whitelist any other type (mapped types, generics, tuples, literals, etc), there is no real way to whitelist template literals.

Fail

// with allowTemplateLiterals: false (default)typeSlashCommand= `/${string}`

Pass

// with allowTemplateLiterals: true (default)typeSlashCommand= `/${string}`

Additional Info

For reference,#5092 (unmerged at the time of creating this issue) adds handling of type literals which are unhandled in current version of the plugin, see#5043

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp