whatsapp-api-js icon indicating copy to clipboard operation
whatsapp-api-js copied to clipboard

Typescript compilation fails on 4.0.0, Cannot find name 'this'

Open yairiff opened this issue 1 year ago • 2 comments

Describe the bug

Typescript fail to compile, that is a simple error that can be fixed in a patch

node_modules/whatsapp-api-js/lib/types/index.d.ts:155:139 - error TS2304: Cannot find name 'this'.

155 broadcastMessage(phoneID: string, to: string[], message: ClientMessage, batch_size?: number, delay?: number): Array<ReturnType<typeof this.sendMessage>>;

Expected behavior tsc should pass...

Desktop (please complete the following information):

  • OS: Windows
  • Runtime node@20
  • Library Version 4.0.0

yairiff avatar Aug 13 '24 14:08 yairiff

Hello there,

This is not the first time I have come across this bug, it has been there since broadcastMessage was created.

Back then I didn't know how to solve it, and I'm guessing I still don't know. If by any chance you have an idea or clue on how to solve it, I would love the input.

Anyway, my best recommendation right now is setting "skipLibCheck": true inside your tsconfig.json, as the error only appears when type-checking the compiled library and it still works with full type support.

That's the annoying thing, it doesn't throw an error while building, only in prod.

I will try to mess with it later today, thanks for raising this issue!

Secreto31126 avatar Aug 13 '24 15:08 Secreto31126

Yes that's exacly what i did, thank you! I think it should be something like typeof WhatsAppAPI['sendMessage'] instead of typeof this.sendMessage

yairiff avatar Aug 13 '24 17:08 yairiff

Oh, wow, I'm just really dumb. I don't know why I never did the obvious thing 🤣.

I will try to do a release in a few hours, thanks for the help!

Secreto31126 avatar Aug 14 '24 09:08 Secreto31126