Skip to content

Commit e8f3eec

Browse files
jaulzcooperka
authored andcommitted
🚀 Add typescript definition file (#38)
* fix: add Typescript definition * fix: add Typescript definition * fix: rename to ImmutableData and only do heuristic check * fix: optimize comment
1 parent d3526ec commit e8f3eec

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

index.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as React from 'react'
2+
import * as Immutable from 'immutable'
3+
import { ListViewProps, VirtualizedListProps } from 'react-native';
4+
5+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
6+
7+
// Heuristic check if data is Immutable
8+
type ImmutableData = {
9+
slice: (begin?: number, end?: number) => any;
10+
keySeq: () => any
11+
}
12+
13+
export type ImmutableListViewProps = Omit<ListViewProps, 'dataSource'> & {
14+
immutableData: ImmutableData,
15+
dataSource?: never,
16+
sectionHeaderHasChanged?: (prevSectionData:any, nextSectionData:any) => boolean,
17+
rowsDuringInteraction?: number,
18+
renderEmpty?: string | React.FC<ImmutableListViewProps>,
19+
renderEmptyInList?: string | React.FC<ImmutableListViewProps>,
20+
}
21+
22+
export declare class ImmutableListView extends React.Component<ImmutableListViewProps> {}
23+
24+
export declare class EmptyListView extends React.Component<Omit<ListViewProps, 'dataSource'> & {
25+
dataSource?: never,
26+
renderRow?: React.FC<any>,
27+
emptyText?: string,
28+
}> {}
29+
30+
export type ImmutableVirtualizedListProps<T> = VirtualizedListProps<T> & {
31+
immutableData: ImmutableData,
32+
renderEmpty?: string | React.FC<ImmutableVirtualizedListProps<T>>,
33+
renderEmptyInList?: string | React.FC<ImmutableVirtualizedListProps<T>>,
34+
}
35+
36+
export declare class ImmutableVirtualizedList<T = any> extends React.Component<ImmutableVirtualizedListProps<T>> {}
37+
38+
export declare class EmptyVirtualizedList<T> extends React.Component<VirtualizedListProps<T> & {
39+
renderItem: React.FC<any>,
40+
emptyText: string
41+
}> {}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.7.5",
44
"description": "Drop-in replacement for React Native's ListView, FlatList, and VirtualizedList.",
55
"main": "lib/index.js",
6+
"types": "index.d.ts",
67
"files": [
78
"lib",
89
"src"

0 commit comments

Comments
 (0)