question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue 3 typecheck fails on `:navigation` because it doesn't recognize the type

See original GitHub issue

Check that this is really a bug

  • I confirm

Reproduction link

Bug description

<template>

<swiper
  slides-per-view="auto"
  :space-between="40"
  :navigation="{
    nextEl: `.swiper-next-${id}`,
    prevEl: `.swiper-prev-${id}`
  }"
  :modules="swiperModules"
>

</template>


This component causes the following typescript error when ran with vue-tsc

Type '{ nextEl: string; prevEl: string; }' is not assignable to type 'undefined'.

55             :navigation="{

Something must be wrong with how the :navigation type is set. Other properties are recognized with no issues.

Expected Behavior

There should not be a typescript error since the data matches the expected type, and type unknown should not be the type of the prop.

Actual Behavior

With the prop having type unknown it is impossible to match any values with it when you have a strict ts implementation.

Swiper version

8.1.4

Platform/Target and Browser Versions

Node 16

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I’m willing to open a PR

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

6reactions
lucassiminescommented, May 19, 2022

@stijn-gravity thanks for the help! I also found another way: I created a file named shim-vue.d.ts and placed in the root directory of the project with the following code:

declare module 'swiper/vue' {
  import { DefineComponent } from 'vue';
  export const Swiper: DefineComponent;
  export const SwiperSlide: DefineComponent;
}
3reactions
iamzzmcommented, May 28, 2022

@stijn-gravity thanks for the help! I also found another way: I created a file named shim-vue.d.ts and placed in the root directory of the project with the following code:

declare module 'swiper/vue' {
  import { DefineComponent } from 'vue';
  export const Swiper: DefineComponent;
  export const SwiperSlide: DefineComponent;
}

Thanks! IT WORKS!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What causes the type check failed for prop error in this Vue 3 ...
As can be seen above, I have explicitly set dataIsLoaded to a boolean. Yet, in the console, I get the error: Invalid prop:...
Read more >
Options: State - Vue.js
In development mode, Vue will check if a prop's value matches the declared type, and will throw a warning if it doesn't. See...
Read more >
TypeScript | WebStorm Documentation - JetBrains
Here you can view problem descriptions, apply quick-fixes, navigate to the fragments in the source code where errors occurred, as well as fix ......
Read more >
Configuring Vitest
Vitest doesn't do static analysis, and cannot fail before your running code, so you will most likely see this error when running tests:....
Read more >
TypeScript support in Svelte - Learn web development
Not true static typing: Types are only checked at compile time, and they are removed from the generated code. Steep learning curve: Even...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found