Skip to content

Commit 1159f1e

Browse files
authored
feat(language-core): align v-for key type with Object.keys (#5837)
1 parent e0fb9e8 commit 1159f1e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
145145
: T extends string ? [string, number][]
146146
: T extends any[] ? [T[number], number][]
147147
: T extends Iterable<infer V> ? [V, number][]
148-
: [T[keyof T], keyof T, number][];
148+
: [T[keyof T], \`\${keyof T}\`, number][];
149149
function __VLS_vSlot<S, D extends S>(slot: S, decl?: D):
150150
D extends (...args: infer P) => any ? P : any[];
151151
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective

test-workspace/tsc/passedFixtures/vue3/v-for/main.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,22 @@
3737
{{ exactType(key, {} as string) }}
3838
{{ exactType(index, {} as number) }}
3939
</div>
40+
<!-- recordNumberKey -->
41+
<div v-for="(val, key, index) in recordNumberKey">
42+
{{ exactType(val, {} as string) }}
43+
{{ exactType(key, {} as '1' | '2' | '3') }}
44+
{{ exactType(index, {} as number) }}
45+
</div>
46+
<!-- recordUnionKey -->
47+
<div v-for="(val, key, index) in recordUnionKey">
48+
{{ exactType(val, {} as string) }}
49+
{{ exactType(key, {} as 'a' | 'b') }}
50+
{{ exactType(index, {} as number) }}
51+
</div>
4052
<!-- any -->
4153
<div v-for="(val, index) in _any">
4254
{{ exactType(val, {} as any) }}
43-
{{ exactType(index, {} as string | number | symbol) }}
55+
{{ exactType(index, {} as string | number) }}
4456
</div>
4557
</template>
4658

@@ -52,5 +64,7 @@ const map = new Map<string, number>();
5264
const obj = { a: '', b: 0 };
5365
const objUnion = { a: '' } as { a: string } | { a: string, b: number };
5466
const record: Record<string, string> = { a: '' };
67+
const recordNumberKey: Record<1 | 2 | 3, string> = { 1: '', 2: '', 3: '' };
68+
const recordUnionKey: Record<'a' | 'b', string> = { 'a': '', 'b': '' };
5569
const _any = {} as any;
5670
</script>

0 commit comments

Comments
 (0)