Resolving Vue and TypeScript Typing Issues

Here's an example of a component:

<script setup type="ts">

interface Props {
    items: string[]
}

const props = defineProps<Props>();

</script>

<template>
    <ul>
        <li v-for="item in props.items">
            {{ item }}
        </li>
    </ul>
</template>

I've encountered the following errors:

  • TypeScript interface declarations can only be used in TypeScript files.
  • An expression was expected but not found.

https://i.sstatic.net/4aJc5CjL.png

The compilation/start process fails with an additional error visible in VS Code:

https://i.sstatic.net/7ogzF0ge.png

Vue official plugin version 2.0.7 is installed.

Here's the content of package.json:

{
  "name": "some-project",
  "private": true,
  "version": "0.1.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "generate": "vite-ssg build",
    "preview": "vite preview",
    "typecheck": "vue-tsc --noEmit"
  },
  "dependencies": {
    "@element-plus/icons-vue": "^2.3.1",
    "@intlify/unplugin-vue-i18n": "^4.0.0",
    "dayjs": "^1.11.11",
    "element-plus": "^2.6.2",
    "oh-vue-icons": "^1.0.0-rc3",
    "pinia": "^2.1.7",
    "unplugin-auto-import": "^0.18.2",
    "unplugin-icons": "^0.19.0",
    "vue": "^3.4.21",
    "vue-i18n": "^9.13.1",
    "vue-router": "^4.4.0"
  },
  "devDependencies": {
    "@iconify-json/ep": "^1.1.15",
    "@types/node": "^22.5.1",
    "@vitejs/plugin-vue": "^5.0.4",
    "sass": "1.77.8",
    "typescript": "^5.4.3",
    "unocss": "^0.62.3",
    "unplugin-vue-components": "^0.27.4",
    "vite": "^5.2.5",
    "vite-ssg": "^0.23.6",
    "vue-tsc": "^2.0.7"
  },
  "license": "MIT"
}

Can someone help me identify the issue?

Answer №1

Is it supposed to be that way?


    <script setup lang="ts"></script>

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

Tips on incorporating Vue.js for creating a reusable modal template?

Currently, I've developed a web app that loads a dynamic dashboard using data from a SQL database. The dashboard elements have buttons that are supposed to trigger modals displaying problem information for user interaction. Lately, I've integrat ...

The initial click does not trigger a Vue DOM update, but subsequent clicks do initiate the update

I developed a Vue application for a dynamic form with two buttons, and I need to indicate which button was clicked in the request. To achieve this, I update the value of a hidden input field and then submit the form using jQuery. However, when I click on t ...

The Vue.js app is functioning properly in the development environment, but it is encountering issues when trying to load the template in the production environment with Rails 5.2.0 and Webpacker

I am currently utilizing Rails 5.2.0 in conjunction with the Webpacker gem for deploying a Vue application. Within the show.html.erb file, the code is very straightforward: <div data-behavior="vue-app"><MyComponent></MyComponent></di ...

An error occurred in Angular2 when attempting to resolve a Promise: The type 'Promise<Hero[]>' is not compatible with the type 'Hero[]'

Recently updated. Currently, I am working through an Angular2 tutorial which can be found at this link Highlighted below is the code snippet for calling the HeroService from heroes.component.ts, Heroes.component.ts import { Component , OnInit } from ...

Exploring the integration of jquery Datatables within a vue.js framework

As a newcomer to Vue, I've been experimenting with integrating Vue with jquery datatables for a project requirement. However, I have come across some issues while trying to combine the two. Despite my efforts in the code snippets below, I have not bee ...

How to pass parameters from a directive to a child component in Angular

I am currently attempting to create a child component that can pass parameters using a directive, but I have not been able to find any tutorials on how to achieve this yet. I have tried looking at some resources, such as this one on Stack Overflow: Get re ...

Understanding the NavigationContainer reference in Typescript and react-navigation

In my current project with react-navigation, I've come across a scenario where I need to navigate from outside of a component (specifically after receiving a push notification). The challenge is that when I use the navigation.navigate method from wit ...

Guide on crafting a query with typeorm query builder to extract specific data from the database

I'm a beginner with typeorm in nodejs/nestjs and I'm struggling to create a query to filter course data by instructor's firstname and lastname, course name, and subject. I've tried using 'where' and 'orWhere' but can ...

What is the best way to retrieve the updated value following a mutation in Vuex?

In my Vuex module, I have a simple setup for managing a global date object: import moment from 'moment'; const state = { date: moment() } // getters const getters = { date: state => state.date, daysInMonth: state => state.dat ...

Tips for displaying a form after clicking with a delay in Angular 7

I need to update some AngularJS code for Angular 7. There is a function that displays a new form below the main one when clicked. HTML <img [hidden]="!skillsToDelete" (click)="showFormDelete(skill)" title="Delete" class="cross" src="../../../assets/i ...

Share a callback function with child components via props

My child container defines Ownprops like this: export interface OwnProps { prop1: string; prop2: "callback function" } I want to pass a callback function from the parent to this child in order to trigger a parent function from the child. However ...

{info: "Access denied due to missing authentication credentials."} while attempting a GET request using simplejwt

I have come across several questions similar to mine, but none of the solutions seem to work for me. I am unable to access the API and I can't figure out why. I tested it with a token in Postman and it returned the correct data. Can someone please poi ...

What is causing vue.js to not update the DOM?

Embarking on my journey to learn Vue, I ultimately settled on it as the preferred choice after exploring React, Angular, and Svelte. I have a basic example that is not functioning correctly, likely due to my lack of comprehension regarding Vue's reac ...

Show content based on dynamically selected dropdown in Angular

I am facing an issue with a dynamic select element in Angular. I am struggling to display the selected values on the view because I cannot seem to create a click event on the dropdown options or access the selected option via a click event on the <selec ...

Should one prioritize learning TypeScript over diving into Angular2?

Should I prioritize learning TypeScript before diving into AngularJS 2? ...

Implement a call feature using ReactJS

My service method involves making a PUT call to an API with an ID parameter. However, I am facing issues with hitting the .put URL. Can someone please verify if this is the correct approach? ENDPOINTS = { SAMPLE: "/sample", }; Below is my ...

What is the best way to activate form fields in Angular 4 following the click of an edit button?

My goal is to implement a specific functionality within the profile page form. Initially, the form fields should be disabled. Upon clicking the edit button, the form fields should become enabled. However, a problem arises when clicking the edit button agai ...

Seeking assistance with my VueJS navbar customization

I am currently working on a vueJS project that involves implementing a login page. I am facing an issue where I need to display the navbar on all pages except for the login page (www.mysite.com/). Is there a way to achieve this? Thank you in advance and ...

Can someone explain how I can extract values from components that have been added using a for each loop in Svelte

Embarking on my journey in frontend development and Svelte, I decided to dive into some experimentation. Here is a counter component with buttons to increment or decrement the number of items: Counter.svelte <script> export let quantity = 0; ...

Learn the steps to assign a Base64 URL to an image source

I am currently facing an issue with an image that is being used with angular-cli: <img src="" style="width: 120px; padding-top: 10px" alt="" id="dishPhoto"> The image has a Base64 url named imgUrl. My intention is to set the image source using the ...