Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 12 additions & 11 deletions packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function* generateGeneric(
yield* body;

const propTypes: string[] = [];
const emitTypes: string[] = [];
const { vueCompilerOptions } = options;

if (ctx.generatedTypes.has(names.PublicProps)) {
Expand All @@ -78,8 +79,6 @@ export function* generateGeneric(
if (options.templateCodegen?.generatedTypes.has(names.InheritedAttrs)) {
propTypes.push(names.InheritedAttrs);
}

const emitTypes: string[] = [];
if (scriptSetupRanges.defineEmits) {
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names.emit}`);
}
Expand All @@ -88,15 +87,17 @@ export function* generateGeneric(
}

yield `return {} as {${newLine}`;
yield ` props: ${propTypes.length ? `${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}> & ` : ``}${
vueCompilerOptions.target >= 3.4
? `import('${vueCompilerOptions.lib}').PublicProps`
: vueCompilerOptions.target >= 3
? `import('${vueCompilerOptions.lib}').VNodeProps`
+ ` & import('${vueCompilerOptions.lib}').AllowedComponentProps`
+ ` & import('${vueCompilerOptions.lib}').ComponentCustomProps`
: `globalThis.JSX.IntrinsicAttributes`
}`;
yield ` props: `;
yield vueCompilerOptions.target >= 3.4
? `import('${vueCompilerOptions.lib}').PublicProps`
: vueCompilerOptions.target >= 3
? `import('${vueCompilerOptions.lib}').VNodeProps`
+ ` & import('${vueCompilerOptions.lib}').AllowedComponentProps`
+ ` & import('${vueCompilerOptions.lib}').ComponentCustomProps`
: `globalThis.JSX.IntrinsicAttributes`;
if (propTypes.length) {
yield ` & ${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}>`;
}
if (!vueCompilerOptions.checkUnknownProps) {
yield ` & (typeof globalThis extends { ${names.PROPS_FALLBACK}: infer P } ? P : {})`;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/tsc/tests/__snapshots__/dts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ export default _default;

exports[`Input: generic/component.vue, Output: generic/component.vue.d.ts 1`] = `
"declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
props: __VLS_PrettifyLocal<({
props: import("vue").PublicProps & __VLS_PrettifyLocal<({
foo: number;
} & {
title?: string;
}) & {
"onUpdate:title"?: (value: string) => any;
onBar?: (data: number) => any;
}> & import("vue").PublicProps & (typeof globalThis extends {
}> & (typeof globalThis extends {
__VLS_PROPS_FALLBACK: infer P;
} ? P : {});
expose: (exposed: import("vue").ShallowUnwrapRef<{
Expand Down Expand Up @@ -202,14 +202,14 @@ type __VLS_PrettifyLocal<T> = (T extends any ? {

exports[`Input: generic/custom-extension-component.cext, Output: generic/custom-extension-component.cext.d.ts 1`] = `
"declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
props: __VLS_PrettifyLocal<({
props: import("vue").PublicProps & __VLS_PrettifyLocal<({
foo: number;
} & {
title?: string;
}) & {
"onUpdate:title"?: (value: string) => any;
onBar?: (data: number) => any;
}> & import("vue").PublicProps & (typeof globalThis extends {
}> & (typeof globalThis extends {
__VLS_PROPS_FALLBACK: infer P;
} ? P : {});
expose: (exposed: import("vue").ShallowUnwrapRef<{
Expand Down
Loading