padlocal/wechaty-puppet-padlocal-demo

Type 'PuppetPadlocal' is not assignable to type 'Puppet'.

forconz opened this issue · 7 comments

PS D:\Projects\Test\wechaty-puppet-padlocal-demo> npm run demo

wechaty-puppet-padlocal-demo@0.1.2 demo
D:/Projects/Test/wechaty-puppet-padlocal-demo/node_modules/.bin/ts-node main.ts

D:\Projects\Test\wechaty-puppet-padlocal-demo\node_modules\ts-node\src\index.ts:513
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
main.ts:13:5 - error TS2322: Type 'PuppetPadlocal' is not assignable to type '"wechaty-puppet-hostie" | "wechaty-puppet-puppeteer" | "wechaty-puppet-service" | "wechaty-puppet-mock" | "wechaty-puppet-wechat" | "wechaty-puppet-wechat4u" | "wechaty-puppet-padlocal" | ... 6 more ... | Puppet'.
Type 'PuppetPadlocal' is not assignable to type 'Puppet'.
Property 'options' is protected but type 'PuppetPadlocal' is not a class derived from 'Puppet'.

13 puppet,
~~~~~~

node_modules/wechaty/dist/src/wechaty.d.ts:13:5
13 puppet?: PuppetModuleName | Puppet;
~~~~~~
The expected type comes from property 'puppet' which is declared here on type 'WechatyOptions'

at createTSError (D:\Projects\Test\wechaty-puppet-padlocal-demo\node_modules\ts-node\src\index.ts:513:12)
at reportTSError (D:\Projects\Test\wechaty-puppet-padlocal-demo\node_modules\ts-node\src\index.ts:517:19)
at getOutput (D:\Projects\Test\wechaty-puppet-padlocal-demo\node_modules\ts-node\src\index.ts:752:36)
at Object.compile (D:\Projects\Test\wechaty-puppet-padlocal-demo\node_modules\ts-node\src\index.ts:968:32)
at Module.m._compile (D:\Projects\Test\wechaty-puppet-padlocal-demo\node_modules\ts-node\src\index.ts:1056:42)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (D:\Projects\Test\wechaty-puppet-padlocal-demo\node_modules\ts-node\src\index.ts:1059:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
GNFu commented

A modification need to be made in creating the bot:
Use
const bot = new Wechaty({ name: "TestBot", puppet: "wechaty-puppet-padlocal", puppetOptions: { token:"token", } })
change token by your own token

iamsk commented

Same issue for me, with mbp, node@14.18.3, token from http://pad-local.com/.

For @GNFu 's solution, still not work, traceback here:

➜ wechaty-puppet-padlocal-demo git:(patch-1) npm run demo

wechaty-puppet-padlocal-demo@0.1.2 demo
./node_modules/.bin/ts-node main.ts

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined
at new NodeError (internal/errors.js:322:7)
at checkListener (events.js:135:11)
at _addListener (events.js:433:3)
at StateSwitch.addListener (events.js:497:10)
at PuppetPadlocal._startClient (/Users/zhangbin/workspace/wechaty-puppet-padlocal-demo/node_modules/wechaty-puppet-padlocal/src/puppet-padlocal.ts:145:20)
at PuppetPadlocal.start (/Users/zhangbin/workspace/wechaty-puppet-padlocal-demo/node_modules/wechaty-puppet-padlocal/src/puppet-padlocal.ts:141:16)
at Wechaty.start (/Users/zhangbin/workspace/wechaty-puppet-padlocal-demo/node_modules/wechaty/src/wechaty.ts:695:25)
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
19:03:20 ERR Wechaty start() exception: The "listener" argument must be of type function. Received undefined
19:03:20 ERR TestBot on error:
19:03:20 WARN Wechaty stop() puppet.stop() exception: The "listener" argument must be of type function. Received undefined
19:03:20 INFO TestBot started.

Yep, confirmed from my end as well:

wechaty-puppet-padlocal-demo/node_modules/ts-node/src/index.ts:513
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
main.ts(13,5): error TS2322: Type 'PuppetPadlocal' is not assignable to type '"wechaty-puppet-hostie" | "wechaty-puppet-puppeteer" | "wechaty-puppet-service" | "wechaty-puppet-mock" | "wechaty-puppet-wechat" | "wechaty-puppet-wechat4u" | "wechaty-puppet-padlocal" | ... 6 more ... | Puppet'.
  Type 'PuppetPadlocal' is missing the following properties from type 'Puppet': cacheContactPayload, cacheFriendshipPayload, cacheMessagePayload, cacheRoomPayload, and 17 more.

    at createTSError (/path/to/wechaty-puppet-padlocal-demo/node_modules/ts-node/src/index.ts:513:12)
    at reportTSError (/path/to/wechaty-puppet-padlocal-demo/node_modules/ts-node/src/index.ts:517:19)
    at getOutput (/path/to/wechaty-puppet-padlocal-demo/node_modules/ts-node/src/index.ts:752:36)
    at Object.compile (/path/to/wechaty-puppet-padlocal-demo/node_modules/ts-node/src/index.ts:968:32)
    at Module.m._compile (/path/to/wechaty-puppet-padlocal-demo/node_modules/ts-node/src/index.ts:1056:42)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (/path/to/wechaty-puppet-padlocal-demo/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)

My env:

node -v; npm -v; npm ls | grep wechaty
v14.19.0
8.5.0
├── wechaty-puppet-padlocal@0.4.2
└── wechaty@0.60.12

huan commented

Have you tried the wechaty@0.68 with Node.js v16?

I think those versions would solve your problem. @AntonioSun

Oh thanks @huan, what's the corresponding wechaty-puppet versions that goes with wechaty@0.68? If I don't specify it, it goes to version 1, and fails my npm install.

huan commented

@AntonioSun never specific a wechaty-puppet version manually because it was highly coupled with the wechaty version.

v1 is not compatible with v0.x

If the wechaty 0.68 works for you, then my suggestion is just to use it.

The PadLocal is preparing to upgrade to support wechaty v1, you can see this PR:

what's the corresponding wechaty-puppet versions that goes with wechaty@0.68?

This is what happened when I don't specify the wechaty-puppet versions:

$ npm list --depth=1 | grep -E 'wechaty|file-'
+-- file-box@0.16.8
+-- wechaty-puppet-padlocal@0.4.2
| +-- wechaty-puppet@1.10.2
`-- wechaty@0.68.6
  +-- wechaty-puppet-service@0.30.2
  +-- wechaty-puppet@0.41.9

If I don't specify it, it goes to version 1.

See the wechaty-puppet@1.10.2 one under wechaty-puppet-padlocal@0.4.2.

Consequently, this is what I get when running ding-dong.js:

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined
    at checkListener (node:events:258:3)
    at _addListener (node:events:553:3)
    at StateSwitch.addListener (node:events:617:10)
    at PuppetPadlocal._startClient (/.../node_modules/wechaty-puppet-padlocal/dist/puppet-padlocal.js:98:24)
    at PuppetPadlocal.start (/.../node_modules/wechaty-puppet-padlocal/dist/puppet-padlocal.js:95:20)
    at Wechaty.start (/.../node_modules/wechaty/dist/src/wechaty.js:524:31)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}
14:35:23 ERR Wechaty start() exception: The "listener" argument must be of type function. Received undefined
14:35:23 ERR StarterBot TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined

Anyway, I now know that the corresponding wechaty-puppet versions that goes with wechaty@0.68 is wechaty-puppet@0.41.9. thx!