Secreto31126 / whatsapp-api-js

A TypeScript server agnostic Whatsapp's Official API framework
MIT License
140 stars 33 forks source link

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

Closed yairiff closed 1 month ago

yairiff commented 1 month ago

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>;

Expected behavior tsc should pass...

Desktop (please complete the following information):

Secreto31126 commented 1 month ago

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!

yairiff commented 1 month ago

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

Secreto31126 commented 1 month ago

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!