Closed alexgrozav closed 3 years ago
Sorry but if we add .ts
to the path, we even can't have component type-checking in <template>
, because TS language service can't recognized xxx.ts
.
Maybe using intermediate files help you?
// script_2.js
export * from './script.ts';
export { default } from './script.ts';
<script src="./script_2.js" />
I understand that, however it's not an elegant solution. Couldn't we programatically discard/remove the .ts
extension if it's there, before proceeding with the type checking? I can look into that, if you'd accept it as a solution.
Couldn't we programatically discard/remove the .ts extension if it's there, before proceeding with the type checking?
Yes that is easy, let me think about it and ask to community.
My current workaround for now is to patch-package
vue-jest
with:
diff --git a/node_modules/vue-jest/lib/process.js b/node_modules/vue-jest/lib/process.js
index 936b5e5..9f1fab5 100644
--- a/node_modules/vue-jest/lib/process.js
+++ b/node_modules/vue-jest/lib/process.js
@@ -36,6 +36,9 @@ module.exports = function (src, filePath, jestConfig) {
var parts = vueCompiler.parseComponent(src, { pad: true })
if (parts.script && parts.script.src) {
+ if (parts.script.lang === 'ts' && !parts.script.src.endsWith('.ts')) {
+ parts.script.src += '.ts'
+ }
parts.script.content = fs.readFileSync(join(filePath, '..', parts.script.src), 'utf8')
}
@eddyerburgh is it possible to patch this in as a v3.0.8 release? So the Vue 2 + (Vite)/(webpack v4 + vue-cli v4) migration eco-system can benefit a little bit from this?
Some communication with Vue author, we will ignore the .ts
, .d.ts
, .tsx
extensions.
Issue: The solution presented for the issue #6 causes
vue-jest
to crash. It cannot resolve the.ts
extension on referenced scripts, and to be fair, it probably shouldn't.Personally, I feel like referencing
./script
instead of./script.ts
is inconsistent with the other references in the code. Any chance we can implement the path resolution in vue-tsc instead?