Skip to content
Advertisement

Typescript map string literal types to uppercase

JavaScript

I would like to have a type b like

JavaScript

So I tried

JavaScript

But that does not do what I want it to do.

Thank you for reading 🙂

Advertisement

Answer

You can now do this with the introduction of Template Literal Types:

JavaScript

TS Playground

In addition to Uppercase<StringType>, there are also the following helper types:

  • Lowercase
  • Capitalize
  • Uncapitalize

They can be used within a Template Literal Types, like below:

JavaScript

TS Playground

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement