Typescript type for alphanumeric and special characters

Viewed 838

I need to define a type for a response which looks like:

TYGOokcgyA9-FQZPM7-evpely6ETEnLyU2yq6hTD_XpTWkPckEP5bFm79hUTtE7rpa6Aiqc6s7xcTXQNNLSClTWtmc7uMIhf-44r3W3d7qY_LkhkGKuv

what type can I use in Typescript for this ?

export interface key {
  key:{what type should go over here?}
}
1 Answers

There are so called Template Literal Types in Typescript that let you define more strictly what kind of value the string may have. However, I think in your case that would just become too complicated.

Why not define it as a simple string and take a look at Regular Expressions (regex)?

With regexes you can verify if a string matches a certain pattern so you could verify its validity before creating the object holding the key or before using it (depends on the context).

Related