Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have project with following devstack (Vue3, Vite, TypeScript) and I'm getting a following error on
v-slot
:
Element implicitly has an 'any' type because expression of type '"default"' can't be used to index type '{} | {}'.
Property 'default' does not exist on type '{} | {}'.ts(7053)
<DataWrapper v-slot="{ values }">
data: {{ values }}
</DataWrapper>
DataWrapper
component injects props to the slot like this
<slot :values="data"></slot>
It does compile and works as expected but the error is still there. Any idea how to solve this? Thanks a million.
–
–
–
–
Have you tried adding type information?
<DataWrapper v-slot="{ values }: { values: any }">
data: {{ values }}
</DataWrapper>
https://www.typescriptlang.org/docs/handbook/variable-declarations.html#property-renaming
If you are using eslint you can also surround the DataWrapper with
<!-- eslint-disable -->
<!-- eslint-enable -->
–
Disable ESLint check for the whole Vue file
/* eslint-disable @typescript-eslint/no-explicit-any */
Write it as a render function so that this:
<template>
<router-view
v-slot="{Component}"
<transition
name="fade"
mode="out-in"
<component
:is="Component"
:key="$route.path"
</transition>
</router-view>
</template>
becomes this:
<template>
<render />
</template>
<script setup lang="ts">
import {h, Transition} from "vue";
import {RouterView, useRoute} from "vue-router";
import type {VNode} from "vue";
const route = useRoute();
const render = () => {
return h(RouterView, null, {
default: ({Component}: {Component: VNode}) => {
return h(Transition, {name: 'fade', mode: 'out-in'}, [
h(Component, {key: route.path}),
</script>
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.