Turns out TypeScript allows you to type your string formats...
Example #1
type MyStringFormat = `${number} ${string} ${number}`;
const valid: MyStringFormat = "1 b 3"
const invalid: MyStringFormat = "a b c"
Example #2
type Unit = 'C' | 'F' | 'K'
type Temp = `${number} ${Unit}`;
const validTemp: Temp = "273 K" // 0 C, 31.73 F
const invalidTemp: Temp = "0 B" // 0C, 31.73F, 273K (no spaces)
Top comments (0)