Skip to content

Commit 75dfc2b

Browse files
cexbrayatpikax
andauthored
fix: type-checking issue with script setup in v2.0.1 (#1601)
* chore: workaround vue-tsc issue vuejs/language-tools#1452 * fix mount overload, allow DefineComponent to infer it's own generics * readding missing parameters * add overload for vue-tsc Co-authored-by: Carlos Rodrigues <[email protected]>
1 parent ae5bc03 commit 75dfc2b

File tree

8 files changed

+88
-59
lines changed

8 files changed

+88
-59
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"vue-class-component": "^8.0.0-rc.1",
6363
"vue-jest": "^5.0.0-alpha.10",
6464
"vue-router": "^4.0.16",
65-
"vue-tsc": "0.35.2",
65+
"vue-tsc": "0.37.8",
6666
"vuex": "^4.0.2"
6767
},
6868
"peerDependencies": {

src/mount.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ const MOUNT_OPTIONS: Array<keyof MountingOptions<any>> = [
5757
'shallow'
5858
]
5959

60+
type ComponentMountingOptions<T> = T extends DefineComponent<
61+
infer PropsOrPropOptions,
62+
any,
63+
infer D,
64+
any,
65+
any
66+
>
67+
? MountingOptions<
68+
Partial<ExtractDefaultPropTypes<PropsOrPropOptions>> &
69+
Omit<
70+
Readonly<ExtractPropTypes<PropsOrPropOptions>> & PublicProps,
71+
keyof ExtractDefaultPropTypes<PropsOrPropOptions>
72+
>,
73+
D
74+
> &
75+
Record<string, any>
76+
: MountingOptions<any>
77+
6078
function getInstanceOptions(
6179
options: MountingOptions<any> & Record<string, any>
6280
): Record<string, any> {
@@ -172,6 +190,11 @@ export function mount<
172190
>
173191
>
174192
>
193+
// component declared by vue-tsc ScriptSetup
194+
export function mount<T extends DefineComponent<any, any, any, any>>(
195+
component: T,
196+
options?: ComponentMountingOptions<T>
197+
): VueWrapper<InstanceType<T>>
175198

176199
// Component declared with no props
177200
export function mount<
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script setup lang="ts"></script>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<template>
22
<div class="ComponentWithoutName">No Name</div>
33
</template>
4+
5+
<script setup lang="ts"></script>

tests/components/Issue1476.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
<button class="field" @click="selectedField = field">
55
{{ field.name }}
66
</button>
7-
<div
8-
v-if="selectedField === field"
9-
class="selectedField"
10-
>
7+
<div v-if="selectedField === field" class="selectedField">
118
{{ field.name }}
129
</div>
1310
</template>
1411
</div>
1512
</template>
1613

1714
<script lang="ts">
18-
export default {
15+
import { defineComponent } from 'vue'
16+
17+
export default defineComponent({
1918
props: {
20-
availableFields: { type: Array, required: true }
19+
availableFields: { type: Array as () => any[], required: true }
2120
},
2221
data: () => ({
23-
selectedField: ''
22+
selectedField: '' as any
2423
})
25-
}
24+
})
2625
</script>

tests/components/Issue425.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
</template>
88

99
<script lang="ts">
10-
export default {
10+
import { defineComponent } from 'vue'
11+
12+
export default defineComponent({
1113
name: 'MyLink',
1214
props: {
1315
name: {
1416
type: String,
1517
required: true
1618
}
1719
}
18-
}
20+
})
1921
</script>

tests/components/ParentComponent.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
<div>child</div>
66
</div>
77
</template>
8+
9+
<script setup lang="ts"></script>

yarn.lock

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,39 +1916,39 @@
19161916
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-2.3.3.tgz#fbf80cc039b82ac21a1acb0f0478de8f61fbf600"
19171917
integrity sha512-SmQLDyhz+6lGJhPELsBdzXGc+AcaT8stgkbiTFGpXPe8Tl1tJaBw1A6pxDqDuRsVkD8uscrkx3hA7QDOoKYtyw==
19181918

1919-
"@volar/code-gen@0.35.2":
1920-
version "0.35.2"
1921-
resolved "https://registry.yarnpkg.com/@volar/code-gen/-/code-gen-0.35.2.tgz#eb7a573139d0cbaee3d7f38b3362ed6e8838ecaa"
1922-
integrity sha512-MoZHuNnPfUWnCNkQUI5+U+gvLTxrU+XlCTusdNOTFYUUAa+M68MH0RxFIS9Ybj4uAUWTcZx0Ow1q5t/PZozo+Q==
1923-
dependencies:
1924-
"@volar/source-map" "0.35.2"
1925-
1926-
"@volar/source-map@0.35.2":
1927-
version "0.35.2"
1928-
resolved "https://registry.yarnpkg.com/@volar/source-map/-/source-map-0.35.2.tgz#7097ca5941b8c01a7fa7f8e66d1195d31c240638"
1929-
integrity sha512-PFHh9wN/qMkOWYyvmB8ckvIzolrpNOvK5EBdxxdTpiPJhfYjW82rMDBnYf6RxCe7yQxrUrmve6BWVO7flxWNVQ==
1930-
1931-
"@volar/vue-code-gen@0.35.2":
1932-
version "0.35.2"
1933-
resolved "https://registry.yarnpkg.com/@volar/vue-code-gen/-/vue-code-gen-0.35.2.tgz#770d00706eec85e1e261461d0b6fd13ebe888792"
1934-
integrity sha512-8H6P8EtN06eSVGjtcJhGqZzFIg6/nWoHVOlnhc5vKqC7tXwpqPbyMQae0tO7pLBd5qSb/dYU5GQcBAHsi2jgyA==
1935-
dependencies:
1936-
"@volar/code-gen" "0.35.2"
1937-
"@volar/source-map" "0.35.2"
1938-
"@vue/compiler-core" "^3.2.36"
1939-
"@vue/compiler-dom" "^3.2.36"
1940-
"@vue/shared" "^3.2.36"
1941-
1942-
"@volar/vue-typescript@0.35.2":
1943-
version "0.35.2"
1944-
resolved "https://registry.yarnpkg.com/@volar/vue-typescript/-/vue-typescript-0.35.2.tgz#e299702c92f2897af7029f8ae685721c0ef13257"
1945-
integrity sha512-PZI6Urb+Vr5Dvgf9xysM8X7TP09inWDy1wjDtprBoBhxS7r0Dg3V0qZuJa7sSGz7M0QMa5R/CBaZPhlxFCfJBw==
1946-
dependencies:
1947-
"@volar/code-gen" "0.35.2"
1948-
"@volar/source-map" "0.35.2"
1949-
"@volar/vue-code-gen" "0.35.2"
1950-
"@vue/compiler-sfc" "^3.2.36"
1951-
"@vue/reactivity" "^3.2.36"
1919+
"@volar/code-gen@0.37.8":
1920+
version "0.37.8"
1921+
resolved "https://registry.yarnpkg.com/@volar/code-gen/-/code-gen-0.37.8.tgz#aedd078cdce99e04671b43c381d153ac42c6fa01"
1922+
integrity sha512-znGxjKs/8TOqkWyarlLDQcCIpzCMt1bUPImLWdJtF2pAkdgZR0YzzXXoWV3eAwcO2JGCeL3lv2jddaswqDeQHQ==
1923+
dependencies:
1924+
"@volar/source-map" "0.37.8"
1925+
1926+
"@volar/source-map@0.37.8":
1927+
version "0.37.8"
1928+
resolved "https://registry.yarnpkg.com/@volar/source-map/-/source-map-0.37.8.tgz#0df8b10eb72201e1b3ded4aa7762462727ad2fa0"
1929+
integrity sha512-wlmzWIPhb7UAz/ZRGh8db5JoFPERjzRIodrdDn4YD9YejDEmxluRZ3vtYgUiGwJmtT/6UtB9YtPJWjr7XeMMNA==
1930+
1931+
"@volar/vue-code-gen@0.37.8":
1932+
version "0.37.8"
1933+
resolved "https://registry.yarnpkg.com/@volar/vue-code-gen/-/vue-code-gen-0.37.8.tgz#6c18b35d1635f3ddf3a7e8f477824ae3f34578cb"
1934+
integrity sha512-q1RaVjgMM2xRZTqIyJuiZaE2LGJIUnLRHScO02T2C26k+1Ah9z61BCOVBvA3BIh+JpPs7AhaAljiVxh7l/7TaA==
1935+
dependencies:
1936+
"@volar/code-gen" "0.37.8"
1937+
"@volar/source-map" "0.37.8"
1938+
"@vue/compiler-core" "^3.2.37"
1939+
"@vue/compiler-dom" "^3.2.37"
1940+
"@vue/shared" "^3.2.37"
1941+
1942+
"@volar/vue-typescript@0.37.8":
1943+
version "0.37.8"
1944+
resolved "https://registry.yarnpkg.com/@volar/vue-typescript/-/vue-typescript-0.37.8.tgz#5ddef614419f33eeef5ec9430693d9ce1f5b96ef"
1945+
integrity sha512-Tcq7r7ArHXgJEGuMmhN9e5h+jj5tS3exygPnw82gnePKPCHhzegYQfBljhJ4GuVshVeheMmKYEJOkQ9pN+K35w==
1946+
dependencies:
1947+
"@volar/code-gen" "0.37.8"
1948+
"@volar/source-map" "0.37.8"
1949+
"@volar/vue-code-gen" "0.37.8"
1950+
"@vue/compiler-sfc" "^3.2.37"
1951+
"@vue/reactivity" "^3.2.37"
19521952

19531953
"@vue/babel-helper-vue-transform-on@^1.0.2":
19541954
version "1.0.2"
@@ -1975,7 +1975,7 @@
19751975
resolved "https://registry.yarnpkg.com/@vue/compat/-/compat-3.2.37.tgz#bd2062a2be88d06046311d5c058aefb17a1d438a"
19761976
integrity sha512-MIYkFAz3Fur1mtZBqrNMYTymlohCQ0ol6vtNb58cqExLSCt63xZaXyiZZYPvS6WaMXfbNBDPXMvU9tO922eFCA==
19771977

1978-
"@vue/[email protected]", "@vue/compiler-core@^3.2.36":
1978+
19791979
version "3.2.36"
19801980
resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.2.36.tgz#2fa44595308c95610602df54dcb69063ba2c8383"
19811981
integrity sha512-bbyZM5hvBicv0PW3KUfVi+x3ylHnfKG7DOn5wM+f2OztTzTjLEyBb/5yrarIYpmnGitVGbjZqDbODyW4iK8hqw==
@@ -1985,7 +1985,7 @@
19851985
estree-walker "^2.0.2"
19861986
source-map "^0.6.1"
19871987

1988-
1988+
"@vue/[email protected]", "@vue/compiler-core@^3.2.37":
19891989
version "3.2.37"
19901990
resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.2.37.tgz#b3c42e04c0e0f2c496ff1784e543fbefe91e215a"
19911991
integrity sha512-81KhEjo7YAOh0vQJoSmAD68wLfYqJvoiD4ulyedzF+OEk/bk6/hx3fTNVfuzugIIaTrOx4PGx6pAiBRe5e9Zmg==
@@ -1995,23 +1995,23 @@
19951995
estree-walker "^2.0.2"
19961996
source-map "^0.6.1"
19971997

1998-
"@vue/[email protected]", "@vue/compiler-dom@^3.2.36":
1998+
19991999
version "3.2.36"
20002000
resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.2.36.tgz#16d911ff163ed5fc8087a01645bf14bb7f325401"
20012001
integrity sha512-tcOTAOiW4s24QLnq+ON6J+GRONXJ+A/mqKCORi0LSlIh8XQlNnlm24y8xIL8la+ZDgkdbjarQ9ZqYSvEja6gVA==
20022002
dependencies:
20032003
"@vue/compiler-core" "3.2.36"
20042004
"@vue/shared" "3.2.36"
20052005

2006-
2006+
"@vue/[email protected]", "@vue/compiler-dom@^3.2.37":
20072007
version "3.2.37"
20082008
resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.2.37.tgz#10d2427a789e7c707c872da9d678c82a0c6582b5"
20092009
integrity sha512-yxJLH167fucHKxaqXpYk7x8z7mMEnXOw3G2q62FTkmsvNxu4FQSu5+3UMb+L7fjKa26DEzhrmCxAgFLLIzVfqQ==
20102010
dependencies:
20112011
"@vue/compiler-core" "3.2.37"
20122012
"@vue/shared" "3.2.37"
20132013

2014-
"@vue/[email protected]", "@vue/compiler-sfc@^3.2.36":
2014+
20152015
version "3.2.36"
20162016
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.2.36.tgz#e5065e7c0e5170ffa750e3c3dd93a29db109d0f2"
20172017
integrity sha512-AvGb4bTj4W8uQ4BqaSxo7UwTEqX5utdRSMyHy58OragWlt8nEACQ9mIeQh3K4di4/SX+41+pJrLIY01lHAOFOA==
@@ -2027,7 +2027,7 @@
20272027
postcss "^8.1.10"
20282028
source-map "^0.6.1"
20292029

2030-
2030+
"@vue/[email protected]", "@vue/compiler-sfc@^3.2.37":
20312031
version "3.2.37"
20322032
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.2.37.tgz#3103af3da2f40286edcd85ea495dcb35bc7f5ff4"
20332033
integrity sha512-+7i/2+9LYlpqDv+KTtWhOZH+pa8/HnX/905MdVmAcI/mPQOBwkHHIzrsEsucyOIZQYMkXUiTkmZq5am/NyXKkg==
@@ -2086,14 +2086,14 @@
20862086
estree-walker "^2.0.2"
20872087
magic-string "^0.25.7"
20882088

2089-
"@vue/[email protected]", "@vue/reactivity@^3.2.36":
2089+
20902090
version "3.2.36"
20912091
resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.2.36.tgz#026b14e716febffe80cd284fd8a2b33378968646"
20922092
integrity sha512-c2qvopo0crh9A4GXi2/2kfGYMxsJW4tVILrqRPydVGZHhq0fnzy6qmclWOhBFckEhmyxmpHpdJtIRYGeKcuhnA==
20932093
dependencies:
20942094
"@vue/shared" "3.2.36"
20952095

2096-
2096+
"@vue/[email protected]", "@vue/reactivity@^3.2.37":
20972097
version "3.2.37"
20982098
resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.2.37.tgz#5bc3847ac58828e2b78526e08219e0a1089f8848"
20992099
integrity sha512-/7WRafBOshOc6m3F7plwzPeCu/RCVv9uMpOwa/5PiY1Zz+WLVRWiy0MYKwmg19KBdGtFWsmZ4cD+LOdVPcs52A==
@@ -2150,12 +2150,12 @@
21502150
"@vue/compiler-ssr" "3.2.37"
21512151
"@vue/shared" "3.2.37"
21522152

2153-
"@vue/[email protected]", "@vue/shared@^3.2.36":
2153+
21542154
version "3.2.36"
21552155
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.2.36.tgz#35e11200542cf29068ba787dad57da9bdb82f644"
21562156
integrity sha512-JtB41wXl7Au3+Nl3gD16Cfpj7k/6aCroZ6BbOiCMFCMvrOpkg/qQUXTso2XowaNqBbnkuGHurLAqkLBxNGc1hQ==
21572157

2158-
2158+
"@vue/[email protected]", "@vue/shared@^3.2.37":
21592159
version "3.2.37"
21602160
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.2.37.tgz#8e6adc3f2759af52f0e85863dfb0b711ecc5c702"
21612161
integrity sha512-4rSJemR2NQIo9Klm1vabqWjD8rs/ZaJSzMxkMNeJS6lHiUjjUeYFbooN19NgFjztubEKh3WlZUeOLVdbbUWHsw==
@@ -5562,12 +5562,12 @@ vue-router@^4.0.16:
55625562
dependencies:
55635563
"@vue/devtools-api" "^6.0.0"
55645564

5565-
vue-tsc@0.35.2:
5566-
version "0.35.2"
5567-
resolved "https://registry.yarnpkg.com/vue-tsc/-/vue-tsc-0.35.2.tgz#85b94027bebc0c6834e0c20b337900468d83b28d"
5568-
integrity sha512-aqY16VlODHzqtKGUkqdumNpH+s5ABCkufRyvMKQlL/mua+N2DfSVnHufzSNNUMr7vmOO0YsNg27jsspBMq4iGA==
5565+
vue-tsc@0.37.8:
5566+
version "0.37.8"
5567+
resolved "https://registry.yarnpkg.com/vue-tsc/-/vue-tsc-0.37.8.tgz#7b78b2a4b5b2f53fdbb2bc06e0e4935576d7c759"
5568+
integrity sha512-geFpG3qxmb7QIDlPeHCvWomsQHfcgFZ280Nbh3Fj/bQ+Bz0pplTE6rjAq/VLelg8KcbchO5PdACexxeS+mCZAA==
55695569
dependencies:
5570-
"@volar/vue-typescript" "0.35.2"
5570+
"@volar/vue-typescript" "0.37.8"
55715571

55725572
55735573
version "3.2.37"

0 commit comments

Comments
 (0)