Skip to content

Recently receiving type errors when building #77

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
2 tasks done
djandrade1 opened this issue Nov 11, 2022 · 5 comments
Open
2 tasks done

Recently receiving type errors when building #77

djandrade1 opened this issue Nov 11, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@djandrade1
Copy link

Checks

Version

0.6.12

Description

I recently just started getting the following type errors trying to build with the Vue version of splide:

app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/components/SplideTrack/SplideTrack.vue(10,46): error TS1444: 'Ref' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/components/Splide/Splide.vue(12,10): error TS1444: 'ComponentConstructor' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/components/Splide/Splide.vue(12,32): error TS1444: 'Options' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/components/SplideTrack/SplideTrack.vue(12,1): error TS1371: This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.
app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/components/Splide/Splide.vue(13,65): error TS1444: 'PropType' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/components/Splide/Splide.vue(13,84): error TS1444: 'Ref' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/constants/events.ts(29,3): error TS1444: 'EventMap' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/plugin/plugin.ts(1,1): error TS1371: This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.
app build: ../node_modules/.pnpm/@Splidejs+vue-splide@0.6.12/node_modules/@splidejs/vue-splide/src/js/plugin/plugin.ts(1,10): error TS1444: 'App' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.

Reproduction Link

No response

Steps to Reproduce

  1. Make use of the the vue-splide components in a new vite vue typescript project
  2. Build the project
    ...

Expected Behaviour

The app builds normally without issue. I am wondering if you bump the main splide version from 4.1.3 to 4.1.4 if that may fix it since there was a type bug report recently reported for that here: Splidejs/splide#1003

@djandrade1 djandrade1 added the bug Something isn't working label Nov 11, 2022
@djandrade1
Copy link
Author

djandrade1 commented Nov 14, 2022

Actually, looking into it more this appears to be an issue with not explicitly marking a type when doing an import. So, for those issues listed above you would need to add type in front of each import. It looks like this is only required in a few places. Would it be possible to get this updated?

Examples:
Splide.vue
From this:
import { ComponentConstructor, Options, Splide } from '@splidejs/splide';
import { computed, defineComponent, onBeforeUnmount, onMounted, PropType, provide, Ref, ref, watch } from 'vue';
To this:
import type { ComponentConstructor, Options, Splide } from '@splidejs/splide';
import { computed, defineComponent, onBeforeUnmount, onMounted, type PropType, provide, type Ref, ref, watch } from 'vue';

SplideTrack.vue
From this:
import { defineComponent, onUpdated, inject, Ref } from 'vue';
import { Splide } from '@splidejs/splide';
To this:
import { defineComponent, onUpdated, inject, type Ref } from 'vue';
import type { Splide } from '@splidejs/splide';

@djandrade1
Copy link
Author

djandrade1 commented Nov 14, 2022

I forked this and resolved it here for reference. Feel free to update your master.
master...djandrade1:vue-splide:master

Vite now requires isolatedModules and preserveValueImports in their tsconfig.json. Please see the latest @vue/tsconfig/tsconfig.json. These commits enable this to work.
excerpt from their new tsconfig.json:
// Required in Vite
"isolatedModules": true,
// For <script setup>
// See https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#preserve-value-imports
"preserveValueImports": true,
// Enforce using import type instead of import for types

@rriixx
Copy link

rriixx commented Feb 10, 2023

i created a PR #82

@toto6038
Copy link

I encountered this issue as well after upgrading to Nuxt 3.8 which enforces verbatimModuleSyntax by default. Setting this option requires using type-only import.

Based on vue-tsc output, I can confirm the errors are caused by following lines:

import { ComponentConstructor, Options, Splide } from '@splidejs/splide';
import { computed, defineComponent, onBeforeUnmount, onMounted, PropType, provide, Ref, ref, watch } from 'vue';

import { defineComponent, onUpdated, inject, Ref } from 'vue';


import { App } from 'vue';

Still waiting #82 to be processed...

@joris-gallot
Copy link

I think the package shouldn’t be exporting typescript files in the build, I made some typescript fixes and changed the build to include only the .js and .d.ts files
If interested: https://github.com/joris-gallot/vue-splide

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants