Template Literal Types with Typescript
16 August 2021
Updated: 03 September 2023
Template literal types provide us a way to combine string types
or enums
in Typescript.
In the below example, we can make use of a string type
called Action
and an enum
called Resource
to define a type which is a combination of an action combined with a resource
Such that the ResourceAction
type is now defined as:
Now, if you’re like me - you probably want your types to be consistent in some way. For this purpose, we can use the Lowercase
type as follows:
Which results in the following types: