Skip to content

Commit

Permalink
fix: align types of v-for with core
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Dec 24, 2024
1 parent ad75e70 commit 29f1d5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 36 deletions.
11 changes: 4 additions & 7 deletions packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,20 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
>>;
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
function __VLS_getVForSourceType(source: number): [number, number, number][];
function __VLS_getVForSourceType(source: string): [string, number, number][];
function __VLS_getVForSourceType(source: number): [number, number][];
function __VLS_getVForSourceType(source: string): [string, number][];
function __VLS_getVForSourceType<T extends any[]>(source: T): [
item: T[number],
key: number,
index: number,
][];
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
key: number,
index: undefined,
index: number,
][];
// #3845
function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
key: number,
index: undefined,
index: number,
][];
function __VLS_getVForSourceType<T>(source: T): [
item: T[keyof T],
Expand Down
46 changes: 17 additions & 29 deletions test-workspace/tsc/passedFixtures/vue3/v-for/main.vue
Original file line number Diff line number Diff line change
@@ -1,65 +1,53 @@
<template>
<!-- number -->
<div v-for="(val, key) in 10">
<div v-for="(val, index) in 10">
{{ exactType(val, {} as number) }}
{{ isNotAnyOrUndefined(val) }}
{{ exactType(key, {} as number) }}
{{ isNotAnyOrUndefined(key) }}
{{ exactType(index, {} as number) }}
</div>
<!-- string -->
<div v-for="(val, key) in 'foo'">
<div v-for="(val, index) in 'foo'">
{{ exactType(val, {} as string) }}
{{ isNotAnyOrUndefined(val) }}
{{ exactType(key, {} as number) }}
{{ isNotAnyOrUndefined(key) }}
{{ exactType(index, {} as number) }}
</div>
<!-- array -->
<div v-for="(val, key) in arr">
<div v-for="(val, index) in arr">
{{ exactType(val, {} as 'a' | 'b') }}
{{ isNotAnyOrUndefined(val) }}
{{ exactType(key, {} as number) }}
{{ isNotAnyOrUndefined(key) }}
{{ exactType(index, {} as number) }}
</div>
<!-- map -->
<div v-for="(val, key) in map">
<div v-for="(val, index) in map">
{{ exactType(val, {} as [string, number]) }}
{{ isNotAnyOrUndefined(val) }}
{{ exactType(key, {} as number) }}
{{ isNotAnyOrUndefined(key) }}
{{ exactType(index, {} as number) }}
</div>
<!-- obj -->
<div v-for="(val, key) in obj">
<div v-for="(val, key, index) in obj">
{{ exactType(val, {} as string | number) }}
{{ isNotAnyOrUndefined(val) }}
{{ exactType(key, {} as 'a' | 'b') }}
{{ isNotAnyOrUndefined(key) }}
{{ exactType(index, {} as number) }}
</div>
<!-- objUnion -->
<div v-for="(val, key) in objUnion">
<div v-for="(val, key, index) in objUnion">
<!-- {{ exactType(val, {} as string | number) }} -->
{{ exactType(val, {} as string) }}
{{ isNotAnyOrUndefined(val) }}
<!-- {{ exactType(key, {} as 'a' | 'b') }} -->
{{ exactType(key, {} as 'a') }}
{{ isNotAnyOrUndefined(key) }}
{{ exactType(index, {} as number) }}
</div>
<!-- record -->
<div v-for="(val, key) in record">
<div v-for="(val, key, index) in record">
{{ exactType(val, {} as string) }}
{{ isNotAnyOrUndefined(val) }}
{{ exactType(key, {} as string) }}
{{ isNotAnyOrUndefined(key) }}
{{ exactType(index, {} as number) }}
</div>
<!-- any -->
<div v-for="(val, key) in _any">
<div v-for="(val, index) in _any">
{{ exactType(val, {} as any) }}
{{ exactType(key, {} as number) }}
{{ isNotAnyOrUndefined(key) }}
{{ exactType(index, {} as number) }}
</div>
</template>

<script setup lang="ts">
import { exactType, isNotAnyOrUndefined } from '../../shared';
import { exactType } from '../../shared';
const arr = ['a', 'b'] as const;
const map = new Map<string, number>();
Expand Down

0 comments on commit 29f1d5f

Please sign in to comment.