error: Parameter ‘x’ of public method from exported class...external module “z” but cannot be named

这篇博客主要记录了一个在TypeScript项目中打包时遇到的错误:'Parameter 'x' of public method from exported class has or is using name 'y' from external module "z" but cannot be named.'。文章详细介绍了报错场景、实际报错信息以及两种解决方案:暴露类型或使用typeof声明类型。作者还分享了自己对错误原理的理解,并提供了相关的参考链接。
摘要由CSDN通过智能技术生成

记录实践中遇到的报错、解决方案和原理,以及参考来源。

Parameter ‘x’ of public method from exported class has or is using name ‘y’ from external module “z” but cannot be named.

报错场景:能正常运行代码,打包的时候报错。

实际报错信息:

Parameter 'db' of public method from exported class has or is using name 'DatabaseHandler' from external module "/app/src/handler/database-handler" but cannot be named.

Parameter 'db' of public method from exported class has or is using name 'DatabaseHandler' from external module "/app/src/handler/database-handler" but cannot be named.

db变量被赋值了DatabaseHandler的单例。其中,文件只对外暴露单例,不暴露类型。

有问题的代码,大概如下:

//in file DatabaseHandler.ts
export default new DatabaseHandler();

//in file Handler.ts
import dbhandler from "./DatabaseHandler"
export default new Handler();
const db = dbhandler;
//实际上db是一个方法的参数。这里改成普通变量能不能重现错
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值