Skip to content

Commit 7c53715

Browse files
so1vejohnsoncodehk
authored andcommitted
fix(language-core): Prettify<T> breaks generics inferencing (#5424)
1 parent 59f8126 commit 7c53715

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function generateGlobalTypes({
140140
type __VLS_ResolveDirectives<T> = {
141141
[K in Exclude<keyof T, keyof __VLS_GlobalDirectives> & string as \`v\${Capitalize<K>}\`]: T[K];
142142
};
143-
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
143+
type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K]; } & {};
144144
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
145145
146146
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type __VLS_WithDefaults<P, D> = {
2424
);
2525
const PrettifyLocal = defineHelper(
2626
`__VLS_PrettifyLocal`,
27-
() => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${endOfLine}`,
27+
() => `type __VLS_PrettifyLocal<T> = { [K in keyof T as K]: T[K]; } & {}${endOfLine}`,
2828
);
2929
const WithSlots = defineHelper(
3030
`__VLS_WithSlots`,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare const _default: <Row extends BaseRow>(__VLS_props: NonNullable<Awaited<t
2222
};
2323
export default _default;
2424
type __VLS_PrettifyLocal<T> = {
25-
[K in keyof T]: T[K];
25+
[K in keyof T as K]: T[K];
2626
} & {};
2727
"
2828
`;
@@ -104,7 +104,7 @@ exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.v
104104
};
105105
export default _default;
106106
type __VLS_PrettifyLocal<T> = {
107-
[K in keyof T]: T[K];
107+
[K in keyof T as K]: T[K];
108108
} & {};
109109
"
110110
`;
@@ -134,7 +134,7 @@ exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: g
134134
};
135135
export default _default;
136136
type __VLS_PrettifyLocal<T> = {
137-
[K in keyof T]: T[K];
137+
[K in keyof T as K]: T[K];
138138
} & {};
139139
"
140140
`;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script setup lang="ts" generic="T extends keyof HTMLElementTagNameMap = 'h1'">
2+
defineProps<
3+
Partial<HTMLElementTagNameMap[T]> & {
4+
as?: T;
5+
}
6+
>();
7+
</script>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script setup lang="ts">
2+
import Child from './child.vue';
3+
</script>
4+
5+
<template>
6+
<Child as="h2" />
7+
</template>

0 commit comments

Comments
 (0)