element-plus
element-plus copied to clipboard
[TypeScript] [form] 在使用pinia配合element-plus时ts报错
Bug Type: TypeScript
Environment
- Vue Version:
3.4.21
- Element Plus Version:
2.6.1
- Browser / OS:
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
- Build Tool:
Vite
Reproduction
Related Component
-
el-form
Reproduction Link
Steps to reproduce
使用 ref
获取 el-form
表单元素
What is Expected?
类型不报错
What is actually happening?
类型报错
Additional comments
错误信息:
如果没有引用 ".pnpm/@[email protected]/node_modules/@vue/shared",则无法命名 "useLoginPannelStore" 的推断类型。这很可能不可移植。需要类型注释。ts(2742)
Perhaps you could follow the prompts and add a type declaration.
Perhaps you could follow the prompts and add a type declaration.
thx
Perhaps you could follow the prompts and add a type declaration.
Environment
- Vue Version:
3.4.27
- Element Plus Version:
2.7.2
- Browser / OS: UserAgent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
- Build Tool:
Vite
problem
when i add the type of the store, my code hint is gone.
but when i remove the StoreDefinition
, and the code hint works again , but alert the error again.
screenshot
code hint
StoreDefinition
remove the code in red rect ,the error will dispear.
你的意思是加了类型声明没有提示,不加会报错?
你的意思是加了类型声明没有提示,不加会报错?
嗯嗯,英语水平不太好,哈哈哈
如果去掉 ref<FormInstance | null>(null)
里那个 FormInstance
就没问题了
看起来像是组件声明打乱了defineStore 的类型推断。🤔
你把FormInstance
换成你本地自定义的组件试试,有没有同样的问题?
看起来像是组件声明打乱了defineStore 的类型推断。🤔
你把
FormInstance
换成你本地自定义的组件试试,有没有同样的问题?
不太会啊,哈哈,怎么操作
关于你这个正常情况下的提示能发个动态图或者视频吗?
关于你这个正常情况下的提示能发个动态图或者视频吗?
好的,等一下
我现在暂时用的解决方案是在我要用的地方直接as,但是这样感觉不好,类型的判断就不对了,不知道有没有更好的办法
看起来应该是 pinia 类型推断不出自定义的组件类型。或许不应该在 store 中直接声明组件引用的变量,只保存单纯的数据。🤔
直接把 tsconfig.app.json
里面的 tsBuildInfoFile
和 composite
去掉应该就可以了。
直接把
tsconfig.app.json
里面的tsBuildInfoFile
和composite
去掉应该就可以了。
🤔确实不报错了
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
此 issue 已被自动锁定,因为关闭后没有任何近期活动。如果有相关 bug,请重新创建一个新 issue。