我想检查一个字符串是否有与联合类型匹配的前缀,例如:
type Prefix = "ABC" | "DEF" | "GHI" ...;
const hasPrefix = (str: string): boolean => {
// I want to check the first 3 characters of the string
// And see if it matches any of the Prefix
// Something like
// if (str.substr(0, 3) === Prefix)
}
https://stackoverflow.com/questions/56728794
复制相似问题