vue + typescript 打字错误

问题描述 投票:0回答:1

示例组件:

<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>

我看到这些错误:

  • 接口声明只能在 TypeScript 文件中使用。
  • 期待表达。

无法编译/启动。在 vs code 中还可以看到一个额外的错误:

Vue官方插件,v2.0.7已安装

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"
}

这有什么问题吗?

typescript vue.js
1个回答
0
投票

不应该是这样吗

enter image description here

致以诚挚的问候

© www.soinside.com 2019 - 2024. All rights reserved.