Skip to content

Commit b2ca816

Browse files
fix(language-core): ensure type consistency for optional boolean props (#5803)
1 parent 0c80460 commit b2ca816

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

packages/language-core/lib/codegen/script/template.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,8 @@ function* generateTemplateCtx(
7777
exps.push([`{} as { $emit: ${emitTypes.join(` & `)} }`]);
7878
}
7979

80-
const { defineProps, withDefaults } = scriptSetupRanges ?? {};
81-
const props = defineProps?.arg
82-
? `typeof ${defineProps.name ?? names.props}`
83-
: defineProps?.typeArg
84-
? withDefaults?.arg
85-
? `__VLS_WithDefaultsGlobal<${names.Props}, typeof ${names.defaults}>`
86-
: `${names.Props}`
87-
: undefined;
88-
if (props) {
89-
propTypes.push(props);
80+
if (scriptSetupRanges?.defineProps) {
81+
propTypes.push(`typeof ${scriptSetupRanges.defineProps.name ?? names.props}`);
9082
}
9183
if (scriptSetupRanges?.defineModel.length) {
9284
propTypes.push(names.ModelProps);

test-workspace/tsc/passedFixtures/vue3/#3779/main.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ defineProps<{
66
</script>
77

88
<template>
9-
<h1>{{ exactType(optionalBoolean, {} as boolean | undefined) }}</h1>
9+
<h1>{{ exactType(optionalBoolean, {} as boolean) }}</h1>
1010
</template>

test-workspace/tsc/passedFixtures/vue3/#3779/named.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ defineProps<{
66
</script>
77

88
<template>
9-
<h1>{{ exactType(optionalBoolean, {} as boolean | undefined) }}</h1>
9+
<h1>{{ exactType(optionalBoolean, {} as boolean) }}</h1>
1010
</template>

0 commit comments

Comments
 (0)