Skip to content

Error Object is possibly 'null'. (2531) with TypeScript #58

@lijiarui

Description

@lijiarui

@#### Wechaty Doctor

Wechaty version: #git[cd7c7dd log for #55]
Darwin x64 version 15.6.0 memory 38/4096 MB
Docker: false

when I try to use the function Room.member(name: string) and Room.has(contact Contact), I can't run wechaty.

the code as follows:

.on('message', m => {
  m.ready()
  .then(msg => {
    const sender  = m.from()
    const msgRoom = m.room()
     if(msgRoom.member("芮芮")){   
       msgRoom.del(msgRoom.member("芮芮"))
     }
...

the error log as follows:

/Users/lijiarui/git/wechaty/node_modules/ts-node/src/index.ts:308
throw new TSError(diagnosticList)
^
TSError: ⨯ Unable to compile TypeScript
orangiss/juzimi.ts (293,18): Object is possibly 'null'. (2531)
orangiss/juzimi.ts (294,17): Object is possibly 'null'. (2531)
orangiss/juzimi.ts: Emit skipped
at getOutput (/Users/lijiarui/git/wechaty/node_modules/ts-node/src/index.ts:308:17)
at /Users/lijiarui/git/wechaty/node_modules/ts-node/src/index.ts:334:18
at Object.compile (/Users/lijiarui/git/wechaty/node_modules/ts-node/src/index.ts:488:17)
at Module.m._compile (/Users/lijiarui/git/wechaty/node_modules/ts-node/src/index.ts:392:44)
at Module._extensions..js (module.js:550:10)
at Object.require.extensions.(anonymous function) as .ts
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)

npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "ts-node" "orangiss/juzimi.ts"
npm ERR! node v6.2.0
npm ERR! npm v3.8.9
npm ERR! code ELIFECYCLE
npm ERR! wechaty@0.4.0 ts-node: ts-node "orangiss/juzimi.ts"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the wechaty@0.4.0 ts-node script 'ts-node "orangiss/juzimi.ts"'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the wechaty package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ts-node "orangiss/juzimi.ts"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs wechaty
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls wechaty
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/lijiarui/git/wechaty/orangiss/npm-debug.log

when I try the code as follows, it works!

.on('message', m => {
  m.ready()
  .then(msg => {
    const sender  = m.from()
    const msgRoom = m.room()
     if((msgRoom as any).member("芮芮")){   
        (msgRoom as any).del((msgRoom as any).member("芮芮"))       
     }
...

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions