Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

增加 Page 中自定义方法/属性类型 #44

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ declare function getApp(): tinyapp.IGetAppResult;
* 接受一个 object 参数,其指定页面的初始数据、生命周期函数、事件处理函数等。
*/
/* tslint:disable:no-unnecessary-generics */
declare function Page<D>(options: tinyapp.PageOptions<D>): void;
declare function Page<D, M>(options: tinyapp.PageOptions<D, M>): void;
/* tslint:enable:no-unnecessary-generics */

/**
* getCurrentPages() 函数用于获取当前页面栈的实例,
* 以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面。
*/
declare function getCurrentPages(): Array<tinyapp.IPageInstance<any>>;
declare function getCurrentPages(): Array<tinyapp.IPageInstance<any, {}>>;

/* tslint:disable:no-unnecessary-generics */
declare function Component<P, D, M extends tinyapp.IComponentMethods>(
Expand Down
11 changes: 5 additions & 6 deletions types/page.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ declare namespace tinyapp {

type SpliceDataMethod = (operations: ISpliceDataOperations, callback?: () => void) => void;

interface IPageInstance<D> extends Record<string, any> {
type IPageInstance<D, M> = M & {
/**
* 页面数据。
*/
Expand Down Expand Up @@ -145,7 +145,7 @@ declare namespace tinyapp {
/**
* Page 实现的接口对象
*/
type PageOptions<D = Record<string, any>> = IPageOptionsMethods
type PageOptions<D = Record<string, any>, M = Record<string, any>> = IPageOptionsMethods
& {
/**
* 初始数据或返回初始化数据的函数, 为对象时所有页面共享。
Expand All @@ -155,9 +155,8 @@ declare namespace tinyapp {
/**
* 事件处理函数集合。
*/
events?: IPageEvents & ThisType<IPageInstance<D>>;

[name: string]: any;
events?: IPageEvents & ThisType<IPageInstance<D, M>>;
}
& ThisType<IPageInstance<D>>;
& M
& ThisType<IPageInstance<D, M>>;
}