Skip to content
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

能否支持slot的类型? #6599

Open
3 tasks done
Groupguanfang opened this issue Dec 5, 2024 · 7 comments · May be fixed by #6603
Open
3 tasks done

能否支持slot的类型? #6599

Groupguanfang opened this issue Dec 5, 2024 · 7 comments · May be fixed by #6603
Labels
feature request New feature or request

Comments

@Groupguanfang
Copy link

Groupguanfang commented Dec 5, 2024

问题的清晰而简明的描述

能否支持slots的类型提示?

image

目前最新版本的volar是能支持slots的类型提示的,甚至能显示出jsdoc:

image

naive ui能否跟进一下?这样会有更好的编码体验的!🙏

建议的解决方案

好像只有新版的defineComponent函数签名才能支持?目前好像大部分的naive ui组件都是用options实现的,切换成新版的defineComponent函数签名工作量会不会太大了?

备选方案

No response

附加上下文

No response

验证

  • 阅读 贡献指南
  • 阅读 文档
  • 检查是否已经存在请求相同功能的问题,以避免创建重复的问题。
@Groupguanfang Groupguanfang added the feature request New feature or request label Dec 5, 2024
@Zheng-Changfu
Copy link
Collaborator

工作量有点大哦

@Groupguanfang
Copy link
Author

今天晚上研究了一下,如果重构options API为这种新版setup API实在是不太现实,但是其实可以用纯类型推断的角度解决这个问题,虽然不是很优雅,而且有点蹩脚哈!

比如NTooltip组件,原来的实现是这样的:

export type TooltipInst = PopoverInst

export const tooltipProps = {
  ...popoverBaseProps,
  ...(useTheme.props as ThemeProps<TooltipTheme>)
}

export type TooltipProps = ExtractPublicPropTypes<typeof tooltipProps>

export default defineComponent({
  name: 'Tooltip',
  props: tooltipProps,
  __popover__: true,
  setup(props) {
  // 一大坨东西
  // ...
  // ...

那么稍微改动一下,不要让这个原来的defineComponent作为默认导出:

const tooltip = defineComponent({
  /** 里面一大坨 */
})

export default tooltip as any as /** 这里开始类型体操🤸 */

然后就很简单了:

// 导出一个TooltipSlots类型供外界使用,并且写上jsdoc注释等...
export interface TooltipSlots {
  /**
   * ## 默认插槽,承载Tooltip的内容
   */
  default?: any
  /**
   * ## 触发插槽,用来定义触发元素
   */
  trigger?: any
}

// 定义新版签名的类型
type OverloadTooltip = (props: TooltipProps, ctx: {
  slots: TooltipSlots
}) => JSX.Element

// 然后导出它
export default tooltip as unknown as OverloadTooltip
image

这样外界就能拿到slots的类型提示了,唯一不好的地方就是要用那刺眼的as unknown as xxx强制转换,就有点麻,但是这样确实能完美的解决问题。

现在需要的是作者同意用这个办法来实现。如果 @07akioni 同意的话,工作量虽然大,但是我平时没什么事做,我来提这个PR也是没问题的;毕竟本身不涉及任何运行时的东西,全是类型体操🤸

@Zheng-Changfu
Copy link
Collaborator

Zheng-Changfu commented Dec 7, 2024 via email

@Zheng-Changfu
Copy link
Collaborator

Zheng-Changfu commented Dec 7, 2024 via email

@Groupguanfang
Copy link
Author

啊🤔️ option api我不太了解,还支持这样的阿,那岂不是更方便了
工作量确实有点大,不过我有点时间,看看我来提交个PR试试吧

Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
Groupguanfang pushed a commit to Groupguanfang/naive-ui that referenced this issue Dec 7, 2024
@Groupguanfang Groupguanfang linked a pull request Dec 7, 2024 that will close this issue
@Groupguanfang
Copy link
Author

手动复制粘贴了几个钟头,终于弄好了。。

@Nakus0426
Copy link
Contributor

牛逼老哥!😂👍,@07akioni 能合并那就太好了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants