Skip to content

fix(language-core): intersect __VLS_slots with __VLS_ctx.$slots #5083

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

Merged
merged 12 commits into from
Feb 12, 2025
Merged
Prev Previous commit
Next Next commit
fix: omit string index from __VLS_ctx.$slots
  • Loading branch information
KazariEX committed Dec 24, 2024
commit 09bda6c967aedef8dfde87f4257921e890acba93
3 changes: 3 additions & 0 deletions packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
>>;
type __VLS_OmitStringIndex<T> = {
[K in keyof T as string extends K ? never : K]: T[K];
};
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;

function __VLS_getVForSourceType(source: number): [number, number, number][];
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function* generateSlots(options: TemplateCodegenOptions, ctx: TemplateCodegenCon
const name = getSlotsPropertyName(options.vueCompilerOptions.target);

if (!options.hasDefineSlots) {
yield `var __VLS_slots!: typeof __VLS_ctx.${name} & `;
yield `var __VLS_slots!: __VLS_OmitStringIndex<typeof __VLS_ctx.${name}> & `;
for (const { expVar, varName } of ctx.dynamicSlots) {
ctx.hasSlot = true;
yield `Partial<Record<NonNullable<typeof ${expVar}>, (_: typeof ${varName}) => any>> &${newLine}`;
Expand Down
12 changes: 9 additions & 3 deletions packages/tsc/tests/__snapshots__/dts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ declare const _default: <Row extends BaseRow>(__VLS_props: NonNullable<Awaited<t
} & Partial<{}>> & (import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps);
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
attrs: any;
slots: {
slots: __VLS_OmitStringIndex<Readonly<{
[name: string]: import("vue").Slot<any>;
}>> & {
default?(_: {
row: Row;
}): any;
Expand Down Expand Up @@ -619,7 +621,9 @@ export {};
exports[`vue-tsc-dts > Input: template-slots/component.vue, Output: template-slots/component.vue.d.ts 1`] = `
"declare function __VLS_template(): {
attrs: Partial<{}>;
slots: {
slots: __VLS_OmitStringIndex<Readonly<{
[name: string]: import("vue").Slot<any>;
}>> & {
'no-bind'?(_: {}): any;
default?(_: {
num: number;
Expand Down Expand Up @@ -721,7 +725,9 @@ type __VLS_WithTemplateSlots<T, S> = T & {
exports[`vue-tsc-dts > Input: template-slots/component-no-script.vue, Output: template-slots/component-no-script.vue.d.ts 1`] = `
"declare function __VLS_template(): {
attrs: Partial<{}>;
slots: {
slots: __VLS_OmitStringIndex<Readonly<{
[name: string]: import("vue").Slot<any>;
}>> & {
'no-bind'?(_: {}): any;
default?(_: {
num: number;
Expand Down
Loading