例如,我要一個靜態quote
方法添加到RegExp
類型:如何將靜態方法添加到現有類型?
RegExp.quote = (text: String) => { ... };
但是,當我嘗試這樣做,我收到以下錯誤:
The property 'quote' does not exist on value of type '{ $1: string; $2: string; $3: string; $4: string; $5: string; $6: string; $7: string; $8: string; $9: string; lastMatch: string; (pattern: string, flags?: string): RegExp; new(pattern: string, flags?: string): RegExp; }'.
我只是試過這個,但它似乎覆蓋了'RegExp'的含義,所以我不能再實例化它。我也收到「重複標識符」錯誤。 – Sam
即使工作,它不適合我旁邊的字符串 – deadManN