Skip to content

Commit

Permalink
feat(core): optimize typings
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 16, 2020
1 parent f135818 commit 9318bfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export class Context {
})
}

plugin <T extends PluginFunction<this>> (plugin: T, options?: T extends PluginFunction<this, infer U> ? U : never): this
plugin <T extends PluginObject<this>> (plugin: T, options?: T extends PluginObject<this, infer U> ? U : never): this
plugin <T extends Plugin<this>> (plugin: T, options?: T extends Plugin<this, infer U> ? U : never) {
if (options === false) return
const ctx = Object.create(this)
Expand Down
22 changes: 11 additions & 11 deletions packages/koishi-core/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,24 @@ export function createGroup (id: number, assignee: number) {
}

export interface UserMethods {
getUser <K extends UserField> (userId: number, fields?: K[]): Promise<Pick<UserData, K | 'id'>>
getUser <K extends UserField> (userId: number, defaultAuthority?: number, fields?: K[]): Promise<Pick<UserData, K | 'id'>>
getUser <K extends UserField> (userId: number, fields?: readonly K[]): Promise<Pick<UserData, K | 'id'>>
getUser <K extends UserField> (userId: number, defaultAuthority?: number, fields?: readonly K[]): Promise<Pick<UserData, K | 'id'>>
getUsers <K extends UserField> (fields?: K[]): Promise<Pick<UserData, K>[]>
getUsers <K extends UserField> (ids: number[], fields?: K[]): Promise<Pick<UserData, K>[]>
getUsers <K extends UserField> (ids: readonly number[], fields?: readonly K[]): Promise<Pick<UserData, K>[]>
setUser (userId: number, data: Partial<UserData>): Promise<any>
observeUser <K extends UserField> (user: number | UserData, fields?: K[]): Promise<User<K>>
observeUser <K extends UserField> (user: number | UserData, defaultAuthority?: number, fields?: K[]): Promise<User<K>>
observeUser <K extends UserField> (user: number | UserData, fields?: readonly K[]): Promise<User<K>>
observeUser <K extends UserField> (user: number | UserData, defaultAuthority?: number, fields?: readonly K[]): Promise<User<K>>
getUserCount (): Promise<number>
}

export interface GroupMethods {
getGroup <K extends GroupField> (groupId: number, fields?: K[]): Promise<Pick<GroupData, K | 'id'>>
getGroup <K extends GroupField> (groupId: number, selfId?: number, fields?: K[]): Promise<Pick<GroupData, K | 'id'>>
getAllGroups <K extends GroupField> (assignees?: number[]): Promise<Pick<GroupData, K>[]>
getAllGroups <K extends GroupField> (fields?: K[], assignees?: number[]): Promise<Pick<GroupData, K>[]>
getGroup <K extends GroupField> (groupId: number, fields?: readonly K[]): Promise<Pick<GroupData, K | 'id'>>
getGroup <K extends GroupField> (groupId: number, selfId?: number, fields?: readonly K[]): Promise<Pick<GroupData, K | 'id'>>
getAllGroups <K extends GroupField> (assignees?: readonly number[]): Promise<Pick<GroupData, K>[]>
getAllGroups <K extends GroupField> (fields?: readonly K[], assignees?: readonly number[]): Promise<Pick<GroupData, K>[]>
setGroup (groupId: number, data: Partial<GroupData>): Promise<any>
observeGroup <K extends GroupField> (group: number | GroupData, fields?: K[]): Promise<Group<K>>
observeGroup <K extends GroupField> (group: number | GroupData, selfId?: number, fields?: K[]): Promise<Group<K>>
observeGroup <K extends GroupField> (group: number | GroupData, fields?: readonly K[]): Promise<Group<K>>
observeGroup <K extends GroupField> (group: number | GroupData, selfId?: number, fields?: readonly K[]): Promise<Group<K>>
getGroupCount (): Promise<number>
}

Expand Down

0 comments on commit 9318bfa

Please sign in to comment.