Skip to content

Commit

Permalink
fix(overload): typescript lint (#622)
Browse files Browse the repository at this point in the history
huan committed Jun 28, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 772a02a commit f7880a1
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/room.ts
Original file line number Diff line number Diff line change
@@ -166,19 +166,9 @@ export class Room extends EventEmitter implements Sayable {
public on(event: 'topic', listener: (this: Room, topic: string, oldTopic: string, changer: Contact) => void): this
public on(event: 'EVENT_PARAM_ERROR', listener: () => void): this

public on(event: RoomEventName, listener: (args: any) => any): this {
public on(event: RoomEventName, listener: (...args: any[]) => any): this {
log.verbose('Room', 'on(%s, %s)', event, typeof listener)

// const thisWithSay = {
// say: (content: string) => {
// return Config.puppetInstance()
// .say(content)
// }
// }
// super.on(event, function() {
// return listener.apply(thisWithSay, arguments)
// })

super.on(event, listener) // Room is `Sayable`
return this
}
@@ -427,8 +417,8 @@ export class Room extends EventEmitter implements Sayable {
* find member by name | roomAlias(alias) | contactAlias
* when use memberAll(name:string), return all matched members, including name, roomAlias, contactAlias
*/
public memberAll(name: string): Contact[]
public memberAll(filter: MemberQueryFilter): Contact[]
public memberAll(name: string): Contact[]

public memberAll(queryArg: MemberQueryFilter | string): Contact[] {
if (typeof queryArg === 'string') {
@@ -515,7 +505,15 @@ export class Room extends EventEmitter implements Sayable {
public member(queryArg: MemberQueryFilter | string): Contact | null {
log.verbose('Room', 'member(%s)', JSON.stringify(queryArg))

const memberList = this.memberAll(queryArg)
let memberList: Contact[]
// ISSUE #622
// error TS2345: Argument of type 'string | MemberQueryFilter' is not assignable to parameter of type 'MemberQueryFilter' #622
if (typeof queryArg === 'string') {
memberList = this.memberAll(queryArg)
} else {
memberList = this.memberAll(queryArg)
}

if (!memberList || !memberList.length) {
return null
}

0 comments on commit f7880a1

Please sign in to comment.