Skip to content

Commit

Permalink
chore: narrow v-for types for object union
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 1, 2023
1 parent 4b27d91 commit 529415e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/vue-language-core/src/utils/directorySharedTypes.ts
Expand Up @@ -55,8 +55,8 @@ export declare function getVForSourceType<T extends { [Symbol.iterator](): Itera
undefined, // index
][];
export declare function getVForSourceType<T>(source: T): [
T extends any ? T[keyof T] : never, // item
T extends any ? keyof T : never, // key
T[keyof T], // item
keyof T, // key
number, // index
][];
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-test-workspace/vue-tsc/v-for/generic.vue
@@ -1,7 +1,7 @@
<template>
<div v-for="(val, key) in ({} as T)">
{{ exactType(val, {} as T extends any ? T[keyof T] : never) }}
{{ exactType(key, {} as T extends any ? keyof T : never) }}
{{ exactType(val, {} as T[keyof T]) }}
{{ exactType(key, {} as keyof T) }}
</div>
</template>

Expand Down
6 changes: 4 additions & 2 deletions packages/vue-test-workspace/vue-tsc/v-for/main.vue
Expand Up @@ -36,9 +36,11 @@
</div>
<!-- objUnion -->
<div v-for="(val, key) in objUnion">
{{ exactType(val, {} as string | number) }}
<!-- {{ exactType(val, {} as string | number) }} -->
{{ exactType(val, {} as string) }}
{{ isNotAnyOrUndefined(val) }}
{{ exactType(key, {} as 'a' | 'b') }}
<!-- {{ exactType(key, {} as 'a' | 'b') }} -->
{{ exactType(key, {} as 'a') }}
{{ isNotAnyOrUndefined(key) }}
</div>
<!-- record -->
Expand Down

0 comments on commit 529415e

Please sign in to comment.