language-tools: [Performance]: .vue.d.ts are not used in TypeScript Project References

Hello.

What I want to do

I want to better organize my codebase. So I began to introduce TypeScript Project References to help cope with performance problems in vscode and also separating tests from implementation thus it was not possible for the implementation files to import the test files. I was inspired by the official TypeScript Project References documentation on https://www.typescriptlang.org/docs/handbook/project-references.html#an-example-project.

What is my problem

However, I keep getting this TypeScript error in vscode and vue-tsc

vue/main.unit.ts:1:18 - error TS6307: File 'vue/main.vue.ts' is not listed within the file list of project 'vue/tsconfig.unit.json'. Projects must list all files or use an 'include' pattern.
  The file is in the program because:
    Imported via './main.vue' from file 'vue/main.unit.ts'
    Imported via './main.vue' from file 'vue/main.vue.ts'

1 import Main from './main.vue';
                   ~~~~~~~~~~~~

  vue/main.vue.ts:42:45
    42 let __VLS_internalComponent!: typeof import('./main.vue')['default'];
                                                   ~~~~~~~~~~~~
    File is included via import here.


Found 1 error.

image

What I expect to get No errors in vscode, npm script build:vue is working the same way as build:ts

To reproduce

Details before reproducing

  • build:ts is building a test files project that is referring to a implementation project that contains only a ts file and it works
  • build:vue is building a tests files project that is referring to a implementation project that contains only a vue file and it doesn’t work.

Is this a bug? Am I missing something?

Thank you.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 31 (3 by maintainers)

Most upvoted comments

Sorry it took so long, the problem should now be resolved by https://github.com/volarjs/volar.js/pull/222.

Add *.vue to the include pattern in your tsconfig.unit.json file

It works but I don’t think it is an acceptable solution. My understanding is that it defeats the purpose of separating tests from implementation. Your solution merge the test files with the implementation thus implementation can now depends on test files.

Am I right or I am missing something? Also, why I don’t have to do it with ts/tsconfig.unit.json that build:ts is using?

Thank you @codethief for creating the new issue. For now, the thing I did for working around the issue was creating two different typescript settings. One for VSCode with extraneous included vue files and one for vue-tsc without extraneous included vue files.

But I am agree that we should not have different typescript settings. Maybe when your issue will be fixed, without extraneous included vue, we can gain some performance in VSCode but it is more a hypothesis that still to be proven.

I have decided to create a new ticket, partially to raise awareness but also because I’ve come to think the issue we started discussing here might be different from the original issue #3526 (even though it’s certainly related) since it only shows up in the IDE, not on the command line (see my edited previous comment). So let’s continue this discussion in the new ticket.

When removing extraneous included vue files in tsconfig.json that is refering a project reference, it works with vue-tsc but there is still an error in vscode with the following message : Cannot find module '***.vue' or its corresponding type declarations. ts-plugin(2307) @johnsoncodehk, is this something you are aware of? BTW, hybrid mode is on but I don’t get the error when hybrid mode is off only in vue files. I still get the error on ts files even if hybrid mode is off.

I just confirmed the new version of vue-tsc (2.0.26) resolved my issue. Thank you!

No problem @johnsoncodehk, I know you are working super hard. Thank you. Can’t wait to test the new version.

So @gtbuchanan, you are confirming me that it doesn’t works in the latest versions of vue, vue-tsc and typescript.

Finally, hacking my way around aliases was more challenging that I tought because we use aliased imports and also relative imports. To make it works, I have to change all my relative imports with aliased imports and it will be too much of a burden to do.

So this issue is still revelant to the following reasons :

  • Fix the performance problem by not compiling many time the same vue files
  • Be more consistant with the native tsc compiler by reusing already .d.vue compiled files
  • Doesn’t need to hack your way through changing paths of aliases causing those two side effects
    • VSCode do navigate to the .d.vue when ctrl-clicking to definition instead of .vue
    • Changing all the relative imports to aliased imports

Update when trying version 2.0.11 with typescript version 5.4.4, there is now a error message in the console.

vue/main.unit.ts(1,18): error TS6305: Output file './vue-out/main.vue' has not been built from source file './vue/main.vue'.