"Encountering issues with importing Splitpanes while using VueJs and TypeScript combination

My VueJS view was originally written in JavaScript using the component "splitpanes" from npm package. The code was functioning well with the following structure:

<template>
 <div>
  <Splitpanes :dbl-click-splitter="false" :horizontal="horizontal">
   <Pane id="pane-video" class="d-flex flex-column">
    ...
   </Pane>
  </Splitpanes>
 </div>
</template>
<script>
import Vue from "vue";
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
export default Vue.extend({
  components: {
    Splitpanes,
    Pane
  },
...
</script>

I decided to switch the code to TypeScript like so:

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import Splitpanes from "splitpanes";
import Pane from "splitpanes";
@Component({
  components: { Splitpanes, Pane }
})
export default class VideoConf extends Vue {

Upon making this change, I encountered an error message in VS Code:

Could not find a declaration file for module 'splitpanes'. 'client-vue/node_modules/splitpanes/dist/splitpanes.common.js' implicitly has an 'any' type. Try npm install @types/splitpanes if it exists or add a new declaration (.d.ts) file containing declare module 'splitpanes';Vetur(7016)

I attempted both solutions provided: npm install @types/splitpanes and creating a shims-splitpanes.d.ts file with "declare module 'splitpanes'". Although the syntax checking error disappeared in VS Code and I could run npm run serve, upon opening the page in the browser, I received:

Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. (and the same error for Pane).

When hovering over the import statement for "splitpanes":

import Splitpanes from "splitpanes"; 

I noticed that it was pointing to the @types folder in node_modules:

module "/Users/lisandro/tmp/aws-chime/client-vue/node_modules/@types/splitpanes/index"

It seems I may be missing something crucial related to @types functionality in a TypeScript project. Any insights or suggestions would be greatly appreciated. Thank you!

Answer №1

After troubleshooting, I was able to resolve my issues by eliminating @types/splitpanes and opting for the subsequent type declaration instead (utilizing the updated splitpanes package).

splitpanes.d.ts:

declare module 'splitpanes' {
    let Splitpanes : any;
    let Pane : any;

    export { Splitpanes, Pane }
}

For instance, here is the sample code from App.vue (demonstrating v-model functionalities):

<template>
    <splitpanes class="default-theme">
        <pane min-size="25">
            <input type="text" v-model="text" />
        </pane>
        <pane min-size="35">
            <p>"{{ text }}"</p>
        </pane>
    </splitpanes>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Splitpanes, Pane } from 'splitpanes';
import 'splitpanes/dist/splitpanes.css';

@Component({
    components: {
        Splitpanes,
        Pane
    }
})
export default class App extends Vue {
    text : string = "";
}
</script>

<style>
.splitpanes {
    height: 5em;
}
.splitpanes__pane {
    text-align: center;
}
</style>

Additionally, I'll include a simplified version of the tsconfig.json file below (adapted from the Vue.js documentation):

{
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "strict": true,
        "moduleResolution": "node",
        "experimentalDecorators": true
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve data upon component mounting and deactivate the query in React-query

When navigating to a search result page, query parameters are passed to useQuery. I want the data to be fetched only when the user clicks the "Search" button after changing the search prompt. I attempted to use enabled: false and call refetch() on button ...

Update a value in the sessionStorage using Angular

I am working on a function that handles checkbox options based on event.target.name. The goal is to add the checkbox option to session storage if it's not already there, and update the value if it exists. However, I'm facing some issues with my c ...

Creating a nested/child route structure within the Angular 2 router

Looking to implement nested routing for mypage/param1/1/param2/2 format in the URL. The first parameter is represented by 1 and the second one by 2. It's imperative that there are always two parameters, otherwise an error should be displayed. However, ...

Unable to access pathways from a separate source

In my app.component.ts file, I have two router outlets defined, one with the name 'popup': @Component({ selector: 'app-main', template: `<router-outlet></router-outlet> <router-outlet name="popup" ...

Rect cannot be resized using mouse events

I am currently working on resizing the rectangle inside the SVG using mouse events. To achieve this, I have created another circle shape at the right bottom edge of the rectangle and implemented resize events on that shape. However, I'm facing an issu ...

How to Generate a Unique URL in Angular 7 Using Typescript

I'm struggling to display or download a .pdf file in my Angular 7 project due to issues with window.URL.createObjectURL. Here's the code snippet I've written: this.userService.getFile(report.id).subscribe( res => { console.log(res) ...

Can Vue.js automatically refresh the display when there are changes in a third-party JSON file?

I'm attempting to achieve a specific goal using Vue, but I'm uncertain if it's feasible given my current struggles in obtaining the desired outcome: An API endpoint returns an array containing multiple objects. While I am able to successfu ...

I am in need of a customized 'container' template that will display MyComponent based on a specific condition known as 'externalCondition'. MyComponent includes the usage of a Form and formValidation functionalities

container.html <div ngIf="externalCondition"> <!--Initially this is false. Later became true --!> <my-component #MyComponentElem > </my-component> <button [disabled]= "!myComponentElemRef.myDetailsF ...

combineLatest will trigger only for the initial event

I am looking to combine 3 events and trigger a service call when any of them are fired. Currently, I am using the combineLatest method, but it seems to only work when the first event is triggered by filterChanged. The issue here is that filterChanged is a ...

The data type 'number' cannot be assigned to the data type 'undefined'. Error code: ts(2322)

I encountered an issue where it's giving me an error stating that type number cannot be assigned to type undefined on the last digit (1) in scale={[1.618, 1, 1]}. Can anyone help me figure out how to resolve this TypeScript error? "use client&quo ...

Vue fails to receive updates from Firestore until the page is manually refreshed

I set out to develop a task tracker app using Vue. As I neared completion of the project, I encountered an issue - when adding a new task, it would not change the reminder status unless I reloaded the page. Here is the code snippet from my Home.vue file: & ...

Data types for keys and values in TypeScript

interface A { a?: number }; interface B { a?: string }; function replicate< Source extends object, Destination extends { [key in keyof Source]?: (1) } >( source: Source, key: keyof Source, destination: Destination, converter: ...

Creating detailed documentation comments for TypeScript within Visual Studio

When using C# with ReSharper and StyleCop, I am able to automatically generate basic documentation comments for methods. This includes sections such as: /// <summary> /// The login. /// </summary> /// <param name="returnUrl" ...

Discovering a method to establish a secure HTTPS REST API connection using an IP address, including the implementation of an SSL certificate

Can anyone help me figure out how to generate an SSL certificate for my IP address so that I can establish a secure connection between my frontend Vue and backend Express via the REST API? I am using NGINX as the web server to serve the frontend, which re ...

Can you provide guidance on how to upload a q-img using a relative path from an object?

I am facing an issue with my Vue 3 / TypeScript app that is using Quasar. I have an object containing the relative path to my images, and I'm attempting to use that path to load the image for a Quasar component q-img. Below is an example of the code: ...

Creating a dynamic URL for route model binding using Axios

I need assistance in creating a Vue Axios URL using slug and id, but I'm facing difficulties. Could someone please lend me a hand? axios.get('http://localhost/BUproject/postsByUser/' + slug / +id) .then(response => { this.po ...

Erase the destination pin on Google Maps

I am currently working on a project that involves displaying hit markers on google maps along with a route from start to finish. Although I have successfully displayed the route, I encountered an issue where both the origin and destination have identical ...

Utilize the class type of a method parameter as the method type for another parameter

Here's a quick example illustrating my desired functionality. // Every time, the ACL class will have a different name such as "UsersACL", etc. export class EventsACL { test(): { read: true, write: true } { } } // This function acts ...

Ensure you wait for the next tick before making any assertions using vitest

Within a composable, I have implemented a reactive primitive foo and a function onFooChange. There is a watcher in this composable that monitors changes to foo and calls onFooChange upon any change. I am looking to write a unit test to verify the executio ...

How can I assign a true or false value to an input variable in HTML using AngularTS?

I copied the following HTML code: <tag-input fullWidth id="inputDir" formControlName="inputDir" [modelAsStrings]="true" [placeholder]="'choice feature'" ...