Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-core): align types of v-for with core #5084

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 0 additions & 5 deletions test-workspace/tsc/passedFixtures/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ type IfEquals<T, U, Y = unknown, N = never> =
(<G>() => G extends T ? 1 : 2) extends
(<G>() => G extends U ? 1 : 2) ? Y : N;
export declare function exactType<T, U>(draft: T & IfEquals<T, U>, expected: U & IfEquals<T, U>): IfEquals<T, U>;

// https://stackoverflow.com/a/49928360
type IfNotAny<T> = 0 extends 1 & T ? never : T;
type IfNotUndefined<T> = Exclude<T, undefined> extends never ? never : T;
export declare function isNotAnyOrUndefined<T>(value: IfNotAny<IfNotUndefined<T>>): void;
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
Loading