This question already has answers here:
TypeScript typings in npm @types org packages
                                
                                    (3个答案)
                                
                        
                去年关闭。
            
        

导入MomentJS导致以下错误:

ERROR in [...] Cannot invoke an expression whose type lacks a call signature. Type 'typeof moment' has no compatible call signatures.


如何解决此错误?

最佳答案

现在,最新版本的MomentJS已定义类型。无需外部输入即可重新安装MomentJS。您还应避免使用命名空间样式的导入,因为此类导入无法调用或构造,并且会在运行时导致失败。

走的路是传统的进口:

import moment from 'moment';

10-06 12:25