记录实践中遇到的报错、解决方案和原理,以及参考来源。
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是一个方法的参数。这里改成普通变量能不能重现错