Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Tagged version of a type #391

Open
Beraliv opened this issue May 1, 2024 · 0 comments
Open

Enhancement: Tagged version of a type #391

Beraliv opened this issue May 1, 2024 · 0 comments
Labels
enhancement New feature or request v10.1

Comments

@Beraliv
Copy link
Collaborator

Beraliv commented May 1, 2024

What

The definition of the problem - https://github.com/type-challenges/type-challenges/tree/main/questions/00697-extreme-tag

It's split into sub-problems:

  • Write a function Tag<B, T extends string> that takes a type B other than null and undefined and returns a type labeled with the string literal type T.
  • GetTags<B> retrieves a list of all tags of a type B.
  • HasTag<B, T extends string> checks if type B is tagged with tag T (and returns true or false)
  • HasTags<B, T extends readonly string[]> checks if type B is tagged in succession with tags from tuple T
  • HasExactTags<B, T extends readonly string[]> checks if the list of all tags of type B is exactly equal to the T tuple
  • Finally, add type UnTag<B>, which removes all tags from type B

Solutions:

Examples

The test cases - https://tsplay.dev/NlKEOw

Additional Info

type-fest has support of the following functions:

@Beraliv Beraliv added enhancement New feature or request v10.1 labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v10.1
Projects
None yet
Development

No branches or pull requests

1 participant