Skip to content

Commit

Permalink
types(runtime-core): Adds type signature for renderList helper (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
znck authored Apr 6, 2020
1 parent da1fb7a commit 4d19636
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions packages/runtime-core/src/helpers/renderList.ts
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down

0 comments on commit 4d19636

Please sign in to comment.