Skip to content

Commit

Permalink
fix: special case handling any for v-for
Browse files Browse the repository at this point in the history
close #3112, close #3108
  • Loading branch information
johnsoncodehk committed May 3, 2023
1 parent e165518 commit 0471b09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/vue-language-core/src/utils/directorySharedTypes.ts
Expand Up @@ -49,6 +49,11 @@ export type GlobalComponents =
// v-for
export declare function getVForSourceType(source: number): [number, number, number][];
export declare function getVForSourceType(source: string): [string, number, number][];
export declare function getVForSourceType<T extends any[]>(source: T): [
T[number], // item
number, // key
number, // index
][];
export declare function getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never, // item
number, // key
Expand Down
7 changes: 7 additions & 0 deletions packages/vue-test-workspace/vue-tsc/v-for/main.vue
Expand Up @@ -50,6 +50,12 @@
{{ exactType(key, {} as string) }}
{{ isNotAnyOrUndefined(key) }}
</div>
<!-- any -->
<div v-for="(val, key) in _any">
{{ exactType(val, {} as any) }}
{{ exactType(key, {} as number) }}
{{ isNotAnyOrUndefined(key) }}
</div>
</template>

<script setup lang="ts">
Expand All @@ -60,4 +66,5 @@ const map = new Map<string, number>();
const obj = { a: '', b: 0 };
const objUnion = { a: '' } as { a: string } | { a: string, b: number };
const record: Record<string, string> = { a: '' };
const _any = {} as any;
</script>

0 comments on commit 0471b09

Please sign in to comment.