element-plus icon indicating copy to clipboard operation
element-plus copied to clipboard

[TypeScript] [form] 在使用pinia配合element-plus时ts报错

Open huankong233 opened this issue 10 months ago • 12 comments

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

Github Repo

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)

image

huankong233 avatar Apr 19 '24 03:04 huankong233

Perhaps you could follow the prompts and add a type declaration.

image

btea avatar Apr 19 '24 06:04 btea

Perhaps you could follow the prompts and add a type declaration.

image

thx

huankong233 avatar Apr 19 '24 07:04 huankong233

Perhaps you could follow the prompts and add a type declaration.

image

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

image image

StoreDefinition

image

remove the code in red rect ,the error will dispear.

huankong233 avatar May 09 '24 14:05 huankong233

你的意思是加了类型声明没有提示,不加会报错?

btea avatar May 09 '24 14:05 btea

你的意思是加了类型声明没有提示,不加会报错?

嗯嗯,英语水平不太好,哈哈哈

如果去掉 ref<FormInstance | null>(null) 里那个 FormInstance 就没问题了

huankong233 avatar May 09 '24 14:05 huankong233

看起来像是组件声明打乱了defineStore 的类型推断。🤔

你把FormInstance换成你本地自定义的组件试试,有没有同样的问题?

btea avatar May 09 '24 14:05 btea

看起来像是组件声明打乱了defineStore 的类型推断。🤔

你把FormInstance换成你本地自定义的组件试试,有没有同样的问题?

不太会啊,哈哈,怎么操作

huankong233 avatar May 09 '24 15:05 huankong233

关于你这个正常情况下的提示能发个动态图或者视频吗?

btea avatar May 10 '24 01:05 btea

关于你这个正常情况下的提示能发个动态图或者视频吗?

好的,等一下

huankong233 avatar May 10 '24 01:05 huankong233

我现在暂时用的解决方案是在我要用的地方直接as,但是这样感觉不好,类型的判断就不对了,不知道有没有更好的办法

image

huankong233 avatar May 10 '24 01:05 huankong233

看起来应该是 pinia 类型推断不出自定义的组件类型。或许不应该在 store 中直接声明组件引用的变量,只保存单纯的数据。🤔

btea avatar May 10 '24 01:05 btea

直接把 tsconfig.app.json 里面的 tsBuildInfoFilecomposite 去掉应该就可以了。

btea avatar May 13 '24 03:05 btea

直接把 tsconfig.app.json 里面的 tsBuildInfoFilecomposite 去掉应该就可以了。

🤔确实不报错了

huankong233 avatar May 13 '24 03:05 huankong233

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。

github-actions[bot] avatar Jun 12 '24 16:06 github-actions[bot]