Typescript引用第三方js库,自己写了声明文件,编译成功后运行代码报错 提示React组件为undefined
发布于 6 年前 作者 huangsav 5458 次浏览 来自 问答

error 如下: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it’s defined in.

Check the render method of DealPicModal.

代码如下,AvatarEditor是第三方component: 图片.png

声明文件如下: 图片.png

原js code: 图片.png 图片.png 图片.png

麻烦大家帮忙看看,谢谢。

6 回复

声明文件有问题? 第二张图那两个interface是否应该添加 export

@waitingsong 试过了,不行,我把改过之后的声明文件和js code结构贴出来了。不知道是不是声明哪里有问题。

有没有大佬帮忙看看

可能是 export import name = … 这种格式有问题

@waitingsong 我换了一种写法,的确可以了,不过还是有bug,component某部分不显示,在调试中。 奇怪,我看有几个React的UI库的声明也是这样写的。。竟然不行。现在将class declare在namespace外面,直接export就能正常识别为一个react的component了。

通常情况没必要使用 namespace

回到顶部