-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
建议:关于APlayer相关接口类型检查报错 #357
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题
我有一个组件按照官方文档使用SFC+ts+
vue-class-component
写的:编译能通过,但是编辑器audio类型检查(以及编译类型检查)报错
检查发现
APlayer.Audio
的类型定义在'@moefe/vue-aplayer/types/aplayer'
,我import了一下,类型检查通过,但是cli编译报错对于webpack来说,从一个非入口
.d.ts
文件import任何内容都是无法编译的,因为根本不存在对应的模块,我引用ElementUI的时候就吃了很多亏。相反,从入口声明文件import 接口是允许的,因为入口声明文件对应的模块存在,而进入babel-loader的时候,会跳过所有的类型检查,无视接口导入。
项目内的临时解决方案
在不改动npm包源码的情况下,要让代码工作通常只有3个方法:
tsconfig.json
中手动引入类型定义,下面这些都是这个问题由于
aplayer.d.ts
用了declare global
的方式,只需要包含类型引入,不必关心实际导入的类型。建议
为了让这些类型定义可以正确的使用,建议修改声明文件的编写方式,可以参考vue的写法。
我个人推荐的使用方式是:
aplayer.d.ts
去除declare global 以及namespace,直接导出所有接口index.d.ts
中导入所有接口,并重新export,这样这些接口可以单独importnamespace APlayer
包含这些接口,然后导出namespace,此时导出APlayer
既是class也是namespace稍后提交pr
The text was updated successfully, but these errors were encountered: