types(runtime-core): Adds type signature for renderList helper (#924)

This commit is contained in:
Rahul Kadyan 2020-04-06 19:27:32 +05:30 committed by GitHub
parent da1fb7afef
commit 4d196366c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,44 @@
import { VNodeChild } from '../vnode'
import { isArray, isString, isObject } from '@vue/shared'
// v-for string
export function renderList(
source: unknown,
renderItem: (
value: unknown,
key: string | number,
index?: number
source: string,
renderItem: (value: string, index: number) => VNodeChild
): VNodeChild[]
// v-for number
export function renderList(
source: number,
renderItem: (value: number, index: number) => VNodeChild
): VNodeChild[]
// v-for array
export function renderList<T>(
source: T[],
renderItem: (value: T, index: number) => VNodeChild
): VNodeChild[]
// v-for iterable
export function renderList<T>(
source: Iterable<T>,
renderItem: (value: T, index: number) => VNodeChild
): VNodeChild[]
// v-for object
export function renderList<T>(
source: T,
renderItem: <K extends keyof T>(
value: T[K],
key: K,
index: number
) => VNodeChild
): VNodeChild[]
// actual implementation
export function renderList(
source: any,
renderItem: (...args: any[]) => VNodeChild
): VNodeChild[] {
let ret: VNodeChild[]
if (isArray(source) || isString(source)) {