"No overload" on socket.send(string, number, string, function)
See original GitHub issueDescription
socket.send()
seems to be incorrectly overloaded when used in a React Native Typescript app. See below for details.
Steps to reproduce
My code:
import dgram from "react-native-udp";
...
sendMessage() {
let socket = dgram.createSocket('udp4');
socket.send("abcd", 64456, "127.0.0.1", (err: Error) => {
if (err) throw err;
console.log('message sent');
});
}
Current behavior
My IDE (VSCode) shows an error on the code above, complaining about an overload error on the 3rd parameter:
No overload matches this call.
The last overload gave the following error.
Argument of type '"127.0.0.1"' is not assignable to parameter of type 'number'. ts(2769)
index.d.ts(58, 7): The last overload is declared here.
When I try to run the code on an Android emulator, I get the error Error: invalid port
. Probably because my address (string) is trying to be interpreted as the port (number).
Expected behavior
The arguments string, number, string, function(Error) => void
should use the msg, port, addr, callback
overload, but it seems to be trying to use a different overload. Perhaps it is defaulting to the msg, offset, length, callback
overload?
Unfortunately I’m quite new to React Native and Typescript so I can’t offer any fixes, but I’m happy to try out possible solutions if need be.
Screenshots Screenshot of error given by IDE Screenshot of error when run on Android emulator
Relevant information
OS | macOS 10.15.6 |
AVD | Pixel 3a API 28, Android 9.0 |
react-native | 4.12.0 |
react-native-udp | 3.2.0 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Gotcha, thanks for the quick response. The code you suggested failed with a similar error, but adding the size parameter works for me 😃.
It seems that index.d.ts includes a function declaration where the parameters are option. Would that be removed in a “complete refresh of the declaration files”?
🎉 This issue has been resolved in version 4.0.0 🎉
The release is available on:
Your semantic-release bot 📦🚀