Declaring string type with min/max length in typescript
You can achieve this using a type constructor and something called a “Phantom Type” (read a nice article about this here) which is a technique to ensure that a type can not be assigned to a value directly. Here’s an example of a StringOfLength<Min,Max> type using these techniques: type StringOfLength<Min, Max> = string & { … Read more