Guide on building a Vue3 component with TypeScript, Pug Template engine, and Composition API

Whenever I try to export components within

<script setup lang="ts">
and then use them in
<template lang="pug">
, an error is thrown stating that the component is defined but never used. Here's an example:

<template lang="pug">
div
  // Even when using kebab-case, like hello-world, the same issue occurs
  HelloWorld
</template>
<script setup lang="ts">
import HelloWorld from'@/components/HelloWorld.vue';
</script>

The error message displayed is: Error: 'HelloWorld' is defined but never used

Answer №1

Here is the solution I came up with:

<template lang="pug">
div
  // Make sure to use kebab-case, such as hello-world, to avoid any issues
  HelloWorld
</template>

<script setup lang="ts">
import HelloWorld from'@/components/HelloWorld.vue';
</script>

<script lang="ts">
export default {
  components: {
    HelloWorld,
  }
}
</script>

The key takeaway here is to clearly define our components. As mentioned on Vue.js documentation, we can use multiple script tags if necessary!

I hope you find this information helpful.

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

Angular 9: Implementing a synchronous *ngFor loop within the HTML page

After receiving a list of subjects from the server, exercises are taken on each subject using the subject.id (from the server) and stored all together in the subEx variable. Classes are listed at the bottom. subjects:Subject[] temp:Exercise[] = [] s ...

A guide on utilizing ESLint to lint expressions within Vue template code

There are some JavaScript/TypeScript expressions in Vue's template, such as {{ a.b }} and v-if="a === -0". I wish for ESLint to be able to lint these expressions in the template. In the image provided, TypeScript code within <script setup ...

The HttpInterceptor is programmed to identify and capture 401 error responses

After successfully implementing a code that called a logout() method upon receiving a 401 response from the server, I encountered issues following an upgrade of Angular from 5.2 to 7.0.3. It seems like either the HttpInterceptor interface has been modified ...

Tips for incorporating a development server proxy with Ionic and Vue

I am interested in utilizing the Proxies feature of Ionic in my Vuejs project built with Ionic. While I have come across solutions for proxy issues in Ionic + Angular and Vue + Webpack projects, I have yet to find a resolution for my specific Ionic + Vue ...

Error message: Material Design UI - The type 'string' cannot be assigned to the type Icon

I am currently working on a component that is responsible for returning the specific icon based on the prop that is passed. Here is a simplified version of how it works in my application: import * as icons from "@mui/icons-material"; interface I ...

Setting up a Vue 3 parent component to emit events to a child component: a step-by-step guide

Seeking assistance with setting up a Vue 3 Tailwind parent component button to trigger a HeadlessUI transition event in a child component. The objective is for the button in the parent to emit an event, which the child will then watch for before triggering ...

Trouble with Vue select not linking to the model

I am working with a basic select element in VueJS: <select v-model="country" class="dropdown-input"> <option v-for="c in countries" v-bind:key="c.CountryCode" v-bind:value="c.CountryCode&q ...

Distribution running of VueJS doesn't show styles

Even though I am able to successfully run my Vuejs app using nom run serve, I am facing an issue when I build it and deploy it to nginx. None of my styles, especially bootstrap, are appearing. Despite my app logic appearing correct and all my js and css ...

What are the steps to effectively implement the useEffect hook in React?

I'm facing an issue where I am trying to return a function that utilizes useEffect from a custom usehook, but I keep getting the error "useEffect is called in a function which is neither a react function component nor a custom hook." Here's what ...

Creating custom TypeScript validation types at compile time

Is it possible to create custom type definitions in TypeScript that are only checked during compile time? I want users to define a value for a variable (that won't change at runtime) and validate if it meets certain criteria. For example, requiring a ...

Define the data type for the toObject function's return value

Is it possible to define the return type of the toObject method in Mongoose? When working with generics, you can set properties of a Document object returned from a Mongoose query. However, accessing getters and setters on these objects triggers various v ...

Adding a dynamic style programmatically to an element created using createElement in Vue: A guide

I have a canvas element that is created programmatically and I am looking to apply a reactive style to it. canvas = document.createElement('canvas') //Apply style this.$refs.parentElement.appendChild(canvas) In a typical scenario, you would u ...

What is the best way to efficiently filter this list of Outcome data generated by neverthrow?

I am working with an array of Results coming from the neverthrow library. My goal is to check if there are any errors in the array and if so, terminate my function. However, the challenge arises when there are no errors present, as I then want to destructu ...

Dealing with Angular 2's Http Map and Subscribe Problem

Looking to parse a JSON file and create a settingsProvider. This is how I am attempting it: import {Http} from "angular2/http"; import {Injectable} from "angular2/core"; @Injectable() export class SettingsProvider{ url: string = ""; constructor ...

Ways to evaluate a String that is thrown using Jest

I encountered a scenario where a function throws a string. Although Jest provides the toThrow matcher for testing functions that throw errors, it only works when an Error object is thrown. Is there a way to test if a string is thrown using Jest? The giv ...

Conceal the header on signup and login pages using Material UI

I am working on a project with three pages: SignUp, Login, and Lists, along with a header component. My goal is to hide the header on the SignUp and Login pages, and only show it on the List page. Any suggestions on how I can achieve this? Here is my cod ...

Error in Typescript: 'SyncClient' not found in Twilio

While working on my Ionic app, I encountered an issue every time I attempted to use the twilio-chat library in my project through npm install. The error consistently appeared in the .d.ts files. Here is how I imported it in my provider : import { Client ...

Leverage the power of Typescript to flatten a JSON model with the help of Class

Currently, I'm exploring how to utilize the class transformer in TypeScript within a Node.js environment. You can find more information about it here: https://github.com/typestack/class-transformer My goal is to flatten a JSON structure using just on ...

Vuetify: Utilizing Time Range Inputs for Start and End Time

I am encountering some difficulty in identifying what I may have missed. I am dealing with 2 inputs: time, startTime, and endTime startTime <v-col cols="12" sm="6" md="2"> <v-menu ref="menu" ...

Decrease the construction duration within a sprawling Angular 8 project

It takes nearly 10-15 minutes to compile the project in production mode, resulting in a dist folder size of 32MB Here are the production options I am currently using:- "production": { "optimization": true, "outputHashing": "all", ...