Skip to content

Commit adeba0a

Browse files
authored
fix(language-core): Prettify<T> caused generic props gets inferred as unknown (#5667)
1 parent 14f63fd commit adeba0a

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

packages/language-core/lib/codegen/globalTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
137137
type __VLS_ResolveDirectives<T> = {
138138
[K in keyof T & string as \`v\${Capitalize<K>}\`]: T[K];
139139
};
140-
type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K]; } & {};
140+
type __VLS_PrettifyGlobal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
141141
type __VLS_WithDefaultsGlobal<P, D> = {
142142
[K in keyof P as K extends keyof D ? K : never]-?: P[K];
143143
} & {

packages/language-core/lib/codegen/localTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ type __VLS_WithDefaultsLocal<P, D> = {
1717
);
1818
const PrettifyLocal = defineHelper(
1919
`__VLS_PrettifyLocal`,
20-
() => `type __VLS_PrettifyLocal<T> = { [K in keyof T as K]: T[K]; } & {}${endOfLine}`,
20+
() =>
21+
`type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {}${endOfLine}`,
2122
);
2223
const WithSlots = defineHelper(
2324
`__VLS_WithSlots`,

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.v
8181
};
8282
declare const _default: typeof __VLS_export;
8383
export default _default;
84-
type __VLS_PrettifyLocal<T> = {
84+
type __VLS_PrettifyLocal<T> = (T extends any ? {
85+
[K in keyof T]: T[K];
86+
} : {
8587
[K in keyof T as K]: T[K];
86-
} & {};
88+
}) & {};
8789
"
8890
`;
8991
@@ -114,9 +116,11 @@ exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: g
114116
};
115117
declare const _default: typeof __VLS_export;
116118
export default _default;
117-
type __VLS_PrettifyLocal<T> = {
119+
type __VLS_PrettifyLocal<T> = (T extends any ? {
120+
[K in keyof T]: T[K];
121+
} : {
118122
[K in keyof T as K]: T[K];
119-
} & {};
123+
}) & {};
120124
"
121125
`;
122126
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script setup lang="ts" generic="T">
2+
defineOptions({ inheritAttrs: false });
3+
defineProps<T>();
4+
</script>
5+
6+
<template>
7+
<slot v-bind="$attrs as T" />
8+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import { exactType } from '../../shared';
3+
import child from './child.vue';
4+
</script>
5+
6+
<template>
7+
<child #default="{ foo, bar }" :foo="42" bar="baz">
8+
{{ exactType(foo, {} as number) }} {{ exactType(bar, {} as string) }}
9+
</child>
10+
</template>

0 commit comments

Comments
 (0)