提交 eec004d0 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix constructor typing unmatch

上级 7154db21
......@@ -163,7 +163,7 @@
"tslint-eslint-rules": "^5.1.0",
"tslint-jsdoc-rules": "^0.1.0",
"tuling123-client": "^0.0.1",
"typescript": "^2.8.3"
"typescript": "^2.9.0-dev.20180509"
},
"files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955",
"files": [
......
......@@ -94,15 +94,16 @@ export interface PuppetOptions {
* Abstract Puppet Class
*/
export abstract class Puppet extends EventEmitter implements Sayable {
public readonly state: StateSwitch
public readonly state : StateSwitch
public readonly classes : PuppetClasses
protected readonly watchdog: Watchdog
private readonly pkg: normalize.Package
constructor(
public options: PuppetOptions,
public classes: PuppetClasses,
public options: PuppetOptions,
classes?: PuppetClasses,
) {
super()
......@@ -114,6 +115,10 @@ export abstract class Puppet extends EventEmitter implements Sayable {
/**
* 1. Check Classes for inherience correctly
*/
if (!classes) {
throw new Error('no classes found')
}
// https://stackoverflow.com/questions/14486110/how-to-check-if-a-javascript-class-inherits-another-without-creating-an-obj
const check = classes.Contact.prototype instanceof Contact
&& classes.FriendRequest.prototype instanceof FriendRequest
......@@ -123,6 +128,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
if (!check) {
throw new Error('Puppet must set classes right! https://github.com/Chatie/wechaty/issues/1167')
}
this.classes = classes
/**
* 2. Load the package.json for Puppet Plugin version range matching
......
......@@ -22,7 +22,7 @@ import * as os from 'os'
import * as semver from 'semver'
import {
// Constructor,
Constructor,
cloneClass,
instanceToClass,
} from 'clone-class'
......@@ -372,10 +372,15 @@ export class Wechaty extends PuppetAccessory implements Sayable {
* 1. Init the Puppet
*/
if (typeof this.options.puppet === 'string') {
puppet = new PUPPET_DICT[this.options.puppet]({
// tslint:disable-next-line:variable-name
const MyPuppet = PUPPET_DICT[this.options.puppet] as typeof Puppet & Constructor<Puppet>
const options = {
profile: this.profile,
wechaty: this,
})
}
puppet = new MyPuppet(options)
} else if (this.options.puppet instanceof Puppet) {
puppet = this.options.puppet
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册