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): correct type narrowing from script to template #4689

Merged
merged 5 commits into from
Aug 25, 2024
Merged
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
Prev Previous commit
Next Next commit
Merge branch 'master' into pr/4689
  • Loading branch information
johnsoncodehk committed Aug 25, 2024
commit 0f51690c76ae6ef7a9615f4bc20c9ba10134c8c2
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function* generateTemplate(
}
const templateCodegenCtx = createTemplateCodegenContext(new Set());
yield `const __VLS_template_return = () => {${newLine}`;
yield* generateCtx(options, ctx, isClassComponent);
yield* generateCtx(options, isClassComponent);
yield* generateTemplateContext(options, templateCodegenCtx);
yield* generateExportOptions(options);
yield* generateConstNameOption(options);
Expand Down
50 changes: 12 additions & 38 deletions packages/tsc/tests/__snapshots__/dts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ declare const _default: <Row extends BaseRow>(__VLS_props: NonNullable<Awaited<t
}> & (import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps);
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
attrs: any;
slots: {
slots: ReturnType<() => {
default?(_: {
row: Row;
}): any;
};
}>;
emit: {};
}>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
Expand Down Expand Up @@ -77,7 +77,7 @@ exports[`vue-tsc-dts > Input: events/component-generic.vue, Output: events/compo
}, never>, "onFoo"> & {}> & (import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps);
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
attrs: any;
slots: {};
slots: ReturnType<() => {}>;
emit: ((evt: "foo", value: string) => void) & {};
}>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
Expand Down Expand Up @@ -108,15 +108,15 @@ exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.v
baz: number;
}>): void;
attrs: any;
slots: Readonly<{
slots: ReturnType<() => Readonly<{
default?(data: {
foo: number;
}): any;
}> & {
default?(data: {
foo: number;
}): any;
};
}>;
emit: ((e: "bar", data: number) => void) & ((evt: "update:title", title: string) => void);
}>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
Expand Down Expand Up @@ -147,15 +147,15 @@ exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: g
baz: number;
}>): void;
attrs: any;
slots: Readonly<{
slots: ReturnType<() => Readonly<{
default?(data: {
foo: number;
}): any;
}> & {
default?(data: {
foo: number;
}): any;
};
}>;
emit: ((e: "bar", data: number) => void) & ((evt: "update:title", title: string) => void);
}>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
Expand All @@ -170,30 +170,8 @@ type __VLS_Prettify<T> = {
`;

exports[`vue-tsc-dts > Input: generic/main.vue, Output: generic/main.vue.d.ts 1`] = `
"declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_OmitIndexSignature<{
"onUpdate:title"?: (title: string) => any;
onBar?: (data: number) => any;
title?: string;
foo: number;
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_OmitIndexSignature<{
"onUpdate:title"?: (title: string) => any;
onBar?: (data: number) => any;
title?: string;
foo: number;
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps>>>>, {}, {}>;
"declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
export default _default;
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
type __VLS_TypePropsToOption<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? {
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
} : {
type: import('vue').PropType<T[K]>;
required: true;
};
};
type __VLS_OmitIndexSignature<T> = {
[K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K];
};
"
`;

Expand Down Expand Up @@ -669,9 +647,8 @@ exports[`vue-tsc-dts > Input: template-slots/component.vue, Output: template-slo
str: string;
}): any;
};
type __VLS_Slots = ReturnType<typeof __VLS_template>['slots'];
declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_Slots>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
Expand Down Expand Up @@ -708,9 +685,8 @@ declare const __VLS_template: () => Readonly<{
}) => VNode[];
'no-bind': () => VNode[];
};
type __VLS_Slots = ReturnType<typeof __VLS_template>['slots'];
declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_Slots>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
Expand All @@ -730,9 +706,8 @@ exports[`vue-tsc-dts > Input: template-slots/component-destructuring.vue, Output
num: number;
}) => any[];
};
type __VLS_Slots = ReturnType<typeof __VLS_template>['slots'];
declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_Slots>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
Expand All @@ -756,9 +731,8 @@ exports[`vue-tsc-dts > Input: template-slots/component-no-script.vue, Output: te
str: string;
}): any;
};
type __VLS_Slots = ReturnType<typeof __VLS_template>['slots'];
declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_Slots>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.