Comments (4)
Hey there, @warmthsea! 👋 Good to see you back here with another insightful observation. How's everything going on your end?
Thank you for providing detailed information about the issue you're facing. It seems like you're encountering a problem with the short syntax of defineSlots
in Volar2+ with vue-macros, where the template slot type is showing as "never". This is likely due to how TypeScript infers types in the context of JSX/TSX and Vue's composition API.
In the vue-macros codebase, the __VLS_DefineSlots<T>
type is designed to transform slot types, ensuring that if a slot is a function, it is used directly; otherwise, it wraps the type in a function that takes the slot type as an argument. This transformation is crucial for Vue's template slot syntax to work correctly with TypeScript's type system.
However, when using the short syntax for slots, TypeScript might not have enough information to correctly infer the slot types, leading to the "never" type. This is because the short syntax does not explicitly define the slot types, and TypeScript's default behavior in the absence of explicit types is to infer the "never" type.
To resolve this issue, you can try the following approaches:
-
Explicit Type Annotations: Ensure that all slots are explicitly typed. This can be done by using the full syntax for slots or by providing explicit type annotations for your slots when using the short syntax. This gives TypeScript the information it needs to correctly infer the slot types.
-
Modify the
__VLS_DefineSlots
Type Definition: If the issue persists, you might need to adjust the__VLS_DefineSlots
type definition to better accommodate TypeScript's type inference mechanisms. This could involve tweaking the type transformation logic to ensure that TypeScript can correctly infer the types of slots, even when using the short syntax. -
Update Volar and vue-macros: Ensure that you are using the latest versions of Volar and vue-macros. It's possible that this issue has been recognized and addressed in newer versions of these tools.
Regarding the difference between the short syntax and the full syntax for defining slots in vue-macros, the short syntax directly specifies the slot as a function type, indicating the type of the scope object that the slot will receive. On the other hand, the full syntax directly specifies the type of the scope object without wrapping it in a function type.
Unfortunately, I couldn't find the exact implementation of the defineSlots
macro in the vue-macros codebase. It might be helpful to look into the source code or the documentation of vue-macros for more details.
I hope this information helps! If you have any more questions or need further clarification, feel free to ask.
Sources
- ✨ Allow using
defineSlots
short syntax in Vue 3.3 - packages/volar/src/define-slots.ts
- playground/vue3/src/examples/define-slots/child.vue
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
from vue-macros.
As docs mentioned https://vue-macros.dev/guide/getting-started.html
❌ Considering that v2 is not yet stable and some issues remain unresolved, plus adapting to 2.x would mean an almost irreversible upgrade for Vue Macros, we've decided not to support 2.x at this time. In other words, we will continue to support v1.
from vue-macros.
from vue-macros.
Thank you for your reply. It seems that I need to change the abbreviation in the project to the official one.
from vue-macros.
Related Issues (20)
- Property 'name' is missing in type 'Plugin<any>[]' but required in type 'Plugin<any>' HOT 2
- Failed to resolve import "@vueuse/core" from "..\..\..\..\vue-macros\define-models\use-vmodel". Does the file exist? HOT 2
- warning: unplugin-vue-better-define SyntaxError: Cannot resolve TS type: X (Nuxt + vue-macros + radix-vue) HOT 6
- vite] Internal server error: At least one <template> or <script> is required in a single file component. HOT 2
- setupSFC error: Illegal tag name. Use '<' to print '<'. HOT 2
- Support conditional properties HOT 4
- Reactivity Transform with Discriminated unions causes type inconsistencies between <script> and<template>
- unplugin-vue-macros 引入的 unplugin-vue-define-options/vue2-macros-global 报错 HOT 1
- 使用 defineModels 的时候应当和直接声明保持一致,是否能详细说明一下 passive 的意义
- [api] support `processDefineProps` to process runtime props HOT 1
- [Vue warn]: Component emitted event "update:rowData" but it is neither declared in the emits option nor as an "onUpdate:rowData" prop. HOT 1
- defineModel触发事件问题 HOT 1
- shortBind already support in v3.4 HOT 1
- withDefaults' first argument must be a defineProps call. HOT 4
- jQuery type conflict HOT 8
- Are there any plans to support rspack? HOT 10
- Is it possible to provide macros for vue2.7 that are only aligned to vue3 via Vue Macros
- Wrong type when using $ref into computed HOT 5
- pnpm monorepo project build error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-macros.