我想知道是否有一种通过TypeScript检查字符串是否与某个模式匹配的方法。
我不想在运行时进行检查。
//What I have now
public id: string; //can be whatever string
//What I want to see
public id: IdType; //Some type?
id = '0000-0000-0000-0001'//valid
id = 'whatever'//invalid
那么这是一种定义字符串格式的方法吗?