Home>
I want to achieve

I'm a beginner who started studying TypeScript, but I'm having trouble specifying the type of a regular expression with typescript.
I got an error when I specified the type of string as a trial.

type regexType = {
  email: string,
  password: string,
}
const regex: regexType = {
  email:/^ [a-zA-Z0-9.! # $%&'* + \/=? ^ _ `{|} ~-] + @ [a-zA-Z0-9] (?: [a -zA-Z0-9-] {0,61} [a-zA-Z0-9])? (?: \. [A-zA-Z0-9] (?: [a-zA-Z0-9-] ] {0,61} [a-zA-Z0-9])?) * $/,
  password:/^ (? =. *? [A-zA-Z]) (? =. *? \ D) [!-\ ~] {8,16} $/,
}
  • Answer # 1

    Regular expression isRegExpThe type.