Skip to content

Structurize template literal types (TemplateLiteralType) #39

@kungfooman

Description

@kungfooman

Example:

/**
 * @typedef {"welcome_email" | "email_heading"} EmailLocaleIDs
 * @typedef {"footer_title" | "footer_sendoff"} FooterLocaleIDs
 * @typedef {`${EmailLocaleIDs | FooterLocaleIDs}_id`} AllLocaleIDs
 * @typedef {"en" | "ja" | "pt"} Lang
 * @typedef {`${Lang}_${AllLocaleIDs}`} LocaleMessageIDs
 */

These templates literal types produce permutations of all input unions, for example:

image

More info: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html

Metadata

Metadata

Assignees

Labels

typingsEverything related to type declarations

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions