Typescript string type that must start with specific characters
As of TypeScript 4.1, you can use a template literal type for this. type StartsWithPrefix = `prefix${string}`; This works for type unions as well: // `abc${string}` | `def${string}` type UnionExample = `${‘abc’ | ‘def’}${string}`; // For your example: type MyPrefixTypes = `${MyStringTypes}${string}`; const ok: UnionExample=”abc123″; const alsoOk: UnionExample=”def123″; const notOk: UnionExample=”abdxyz”; // Note that a … Read more