Skip to content

v2.2.10 #5332

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 6 commits into from
Apr 22, 2025
Merged

v2.2.10 #5332

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
fix(language-core): prevent global types generation in declaration fi…
…les (#5239)
  • Loading branch information
KazariEX committed Apr 22, 2025
commit 51db8967f36152e928b5ad9747b30e08815a45db
3 changes: 0 additions & 3 deletions packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ export function generateGlobalTypes({
'__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<T extends number | string | any[] | Iterable<any>>(source: T): [
Expand Down
5 changes: 2 additions & 3 deletions packages/language-core/lib/codegen/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ function* generateSlots(
ctx: TemplateCodegenContext
): Generator<Code> {
if (!options.hasDefineSlots) {
const name = getSlotsPropertyName(options.vueCompilerOptions.target);
yield `type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${name}>`;
yield `type __VLS_Slots = {}`;
for (const { expVar, propsVar } of ctx.dynamicSlots) {
yield `${newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
}
Expand All @@ -106,7 +105,7 @@ function* generateSlots(
}
yield `?: (props: typeof ${slot.propsVar}) => any }`;
}
yield `>${endOfLine}`;
yield `${endOfLine}`;
}
return `__VLS_Slots`;
}
Expand Down
16 changes: 6 additions & 10 deletions packages/tsc/tests/__snapshots__/dts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -595,25 +595,23 @@ export {};
`;

exports[`vue-tsc-dts > Input: template-slots/component.vue, Output: template-slots/component.vue.d.ts 1`] = `
"declare const __VLS_ctx: InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>;
declare var __VLS_1: {}, __VLS_3: {
"declare var __VLS_1: {}, __VLS_3: {
num: number;
}, __VLS_5: {
str: string;
}, __VLS_7: {
num: number;
str: string;
};
type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & {
type __VLS_Slots = {} & {
'no-bind'?: (props: typeof __VLS_1) => any;
} & {
default?: (props: typeof __VLS_3) => any;
} & {
'named-slot'?: (props: typeof __VLS_5) => any;
} & {
vbind?: (props: typeof __VLS_7) => any;
}>;
declare const __VLS_self: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
};
declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
export default _default;
Expand Down Expand Up @@ -669,25 +667,23 @@ type __VLS_WithSlots<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 const __VLS_ctx: InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>;
declare var __VLS_1: {}, __VLS_3: {
"declare var __VLS_1: {}, __VLS_3: {
num: number;
}, __VLS_5: {
str: string;
}, __VLS_7: {
num: number;
str: string;
};
type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & {
type __VLS_Slots = {} & {
'no-bind'?: (props: typeof __VLS_1) => any;
} & {
default?: (props: typeof __VLS_3) => any;
} & {
'named-slot'?: (props: typeof __VLS_5) => any;
} & {
vbind?: (props: typeof __VLS_7) => any;
}>;
declare const __VLS_self: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
};
declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
export default _default;
Expand Down
5 changes: 2 additions & 3 deletions test-workspace/tsc/passedFixtures/vue3/slots/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<script lang="ts">
export default {
name: 'Self',
slots: Object as SlotsType<{ foo?: (props: any) => any }>,
};

declare const Comp: new <T>(props: { value: T; }) => {
Expand All @@ -42,15 +41,15 @@ declare const Comp: new <T>(props: { value: T; }) => {
</script>

<script lang="ts" setup>
import { ref, type SlotsType, useSlots, type VNode } from 'vue';
import { ref, useSlots, type VNode } from 'vue';
import { exactType } from '../../shared';

const baz = ref('baz' as const);

const slots = useSlots();
exactType(slots, {} as {
readonly foo?: (props: any) => any;
bar?: (props: { str: string; num: number; }) => any;
} & {
baz?: (props: { str: string; num: number; }) => any;
});
</script>