Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-core): should not make $props optional #4878

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
? T | __VLS_unknownDirective
: NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
T extends new (...args: any) => any
Expand Down
3 changes: 1 addition & 2 deletions packages/language-core/lib/codegen/script/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export function* generateComponent(
export function* generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code> {
// fill $props
if (scriptSetupRanges.props.define) {
// NOTE: defineProps is inaccurate for $props
yield `$props: __VLS_makeOptional(${scriptSetupRanges.props.name ?? `__VLS_props`}),${newLine}`;
yield `$props: ${scriptSetupRanges.props.name ?? `__VLS_props`},${newLine}`;
Comment on lines -56 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is correct in general.

Try with a component with props:

  msg: {
    type: String,
    default: null
  }

In that case the prop should be optional but won't.

I feel like that might need coordination with changes in Vue types.

Copy link
Member

@johnsoncodehk johnsoncodehk Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just add a test case in 3557d8b (#4878) for this.

yield `...${scriptSetupRanges.props.name ?? `__VLS_props`},${newLine}`;
}
// fill $emit
Expand Down
8 changes: 8 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4876/child.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script setup>
defineProps({
msg: {
type: String,
required: true
}
})
</script>
8 changes: 8 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4876/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script lang="ts" setup>
import Child from './child.vue';
</script>

<template>
<!-- @vue-expect-error -->
<Child />
</template>