Component error with types from *.d.ts files. #7483
-
I created new Vue project and added src/app.d.ts: interface Test {
a: number;
b: number;
} In App.vue I tried to use it: <script setup lang="ts">
import HelloWorld from "./components/HelloWorld.vue";
import TheWelcome from "./components/TheWelcome.vue";
const k: Test = {
a: 1,
b: 2,
};
console.log(k);
</script> And have error: Please help to solve this. It is very frustrating to start fresh project and to have problem with very simple task. Repo:demo |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
The error is coming from Eslint, the linter. Not Typescript. So you would need to tell Eslint about a global named Test: // .eslintrc.cjs
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')
module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier'
],
parserOptions: {
ecmaVersion: 'latest'
},
globals: {
Test: 'readonly'
}
} |
Beta Was this translation helpful? Give feedback.
-
I just created a fresh project and don't get an error. again, I don't see why TS should check the JS file and complain about missing types. It does not do that for me. Seems to be a setting with your VSCode.
Indeed. Guess I never noticed because I always copy my own settings into any new projects right away. Will talk with soda about this. For now, do one simple
That may have to be address with PHPStorm, or answered by someone using PHPStorm. Jetbrains IDEs usually have great support for Vue from what I heard from users. I can't help with that as I never used their Products, though. |
Beta Was this translation helpful? Give feedback.
I just created a fresh project and don't get an error. again, I don't see why TS should check the JS file and complain about missing types. It does not do that for me. Seems to be a setting with your VSCode.
Indeed. Guess I never noticed because I always copy my own settings into any new projects right away. Will talk with soda about this.
For now, do one simple
npm run lint
to fix all of these initially.