From 541cf78f9d742ea672ef4be3bb15a41bd1e8abd0 Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Mon, 28 Sep 2020 21:54:35 +0800 Subject: [PATCH 1/3] Fix #2314 --- server/src/services/typescriptService/preprocess.ts | 7 +++++-- .../fixture/diagnostics/propTypeValidation/TSChild.vue | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/src/services/typescriptService/preprocess.ts b/server/src/services/typescriptService/preprocess.ts index ff7bc6bbf5..04ad59b6e4 100644 --- a/server/src/services/typescriptService/preprocess.ts +++ b/server/src/services/typescriptService/preprocess.ts @@ -299,10 +299,13 @@ function convertChildComponentsInfoToSource(childComponents: ChildComponent[]) { const propTypeStrings: string[] = []; c.info?.componentInfo.props?.forEach(p => { - let typeKey = p.required ? kebabCase(p.name) : kebabCase(p.name) + '?'; - if (typeKey.indexOf('-') !== -1) { + let typeKey = kebabCase(p.name); + if (typeKey.includes('-')) { typeKey = `'` + typeKey + `'`; } + if (!p.required) { + typeKey += '?'; + } if (p.typeString) { propTypeStrings.push(`${typeKey}: ${p.typeString}`); diff --git a/test/interpolation/fixture/diagnostics/propTypeValidation/TSChild.vue b/test/interpolation/fixture/diagnostics/propTypeValidation/TSChild.vue index ba7afd6c34..b4b71c2e00 100644 --- a/test/interpolation/fixture/diagnostics/propTypeValidation/TSChild.vue +++ b/test/interpolation/fixture/diagnostics/propTypeValidation/TSChild.vue @@ -8,7 +8,8 @@ export default Vue.extend({ callback: { type: Function as PropType<() => void> }, - arr: Array as PropType + arr: Array as PropType, + darkMode: { type: Boolean, default: false } } }); From a759bd5590f081a49e163dfad77a6a4c8340d26a Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Mon, 28 Sep 2020 22:07:52 +0800 Subject: [PATCH 2/3] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fac5155330..670e9037bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - 🙌 Respect typescript language settings. Thanks to contribution from [@yoyo930021](https://github.com/yoyo930021). #2109 and #2375. - 🙌 Slim syntax highlighting. Thanks to contribution from [@Antti](https://github.com/Antti). - 🙌 Stop computing outdated diagnostics with CancellationToken. Thanks to contribution from [@yoyo930021](https://github.com/yoyo930021). #1263 and #2332. +- 🙌 Fix error when optional camel-cased props are missing. Thanks to contribution from [@yoyo930021](https://github.com/yoyo930021). #2314 and #2342. ### 0.28.0 | 2020-09-23 | [VSIX](https://marketplace.visualstudio.com/_apis/public/gallery/publishers/octref/vsextensions/vetur/0.28.0/vspackage) From ed77808968bbee33cbdb503508a27423da9c6d1b Mon Sep 17 00:00:00 2001 From: Pine Wu Date: Fri, 30 Oct 2020 09:45:07 +0800 Subject: [PATCH 3/3] Clean up --- .../fixture/diagnostics/propTypeValidation/TSChild.vue | 2 +- test/vue3/fixture/diagnostics/propTypeValidation/TSChild.vue | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/interpolation/fixture/diagnostics/propTypeValidation/TSChild.vue b/test/interpolation/fixture/diagnostics/propTypeValidation/TSChild.vue index b4b71c2e00..32d9b254b3 100644 --- a/test/interpolation/fixture/diagnostics/propTypeValidation/TSChild.vue +++ b/test/interpolation/fixture/diagnostics/propTypeValidation/TSChild.vue @@ -9,7 +9,7 @@ export default Vue.extend({ type: Function as PropType<() => void> }, arr: Array as PropType, - darkMode: { type: Boolean, default: false } + camelCase: { type: Boolean, default: false } } }); diff --git a/test/vue3/fixture/diagnostics/propTypeValidation/TSChild.vue b/test/vue3/fixture/diagnostics/propTypeValidation/TSChild.vue index 93b0ff8d68..d805184359 100644 --- a/test/vue3/fixture/diagnostics/propTypeValidation/TSChild.vue +++ b/test/vue3/fixture/diagnostics/propTypeValidation/TSChild.vue @@ -8,7 +8,8 @@ export default defineComponent({ callback: { type: Function as PropType<() => void> }, - arr: Array as PropType + arr: Array as PropType, + camelCase: { type: Boolean, default: false } } });