question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"No overload" on socket.send(string, number, string, function)

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Cazfricommented, Aug 24, 2020

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”?

0reactions
github-actions[bot]commented, Aug 30, 2020

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't overload python socket.send - Stack Overflow
As we can see, send method is not overloaded. from socket import socket class PolySocket(socket): def __init__ ...
Read more >
Socket.Send Method (System.Net.Sockets) | Microsoft Learn
Overloads. Sends the specified number of bytes of data to a connected Socket, starting at the specified offset, and using the specified SocketFlags....
Read more >
error: call of overloaded 'function(x)' is ambiguous
In Function overloading, sometimes a situation can occur when the compiler is unable to choose between two correctly overloaded functions. This ...
Read more >
Communicating with sockets (SFML / Learn / 2.5 Tutorials)
A socket is the interface between your application and the outside world: through a socket, you can send and receive data. Therefore, any...
Read more >
3. Data model — Python 3.11.1 documentation
The string representations of the numeric classes, computed by __repr__() and __str__() ... The function's documentation string, or None if unavailable; not ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found