I'm trying to convert a piece of code to TypeScript and I've run into an issue with a Buffer
that I use with a UDP socket.
The code I'm working with looks like this:
/// <reference path="../node_modules/DefinitelyTyped/node/node.d.ts" />
import dgram = require( "dgram" );
var udpServer:dgram.Socket = dgram.createSocket( "udp4" );
var message = new Buffer( "foo" );
udpServer.send( message, 0, message.length, 1337, "255.255.255.255" );
WebStorm complains about message
with the error Argument type Buffer is not assignable to argument type NodeBuffer
.
I understand that this is due to the fact that Socket.send()
requires a NodeBuffer
as the first argument and I'm supplying a Buffer
. But how can I overcome this?
I can't use NodeBuffer
as the type of message
, that just leads to different errors.
var message:NodeBuffer = new Buffer( "foo" );
Will lead to Initializer type Buffer is not assignable to variable type NodeBuffer
var message:NodeBuffer = new NodeBuffer( "foo" );
Will lead to Argument types do not match parameters
.
This is confusing me due to the examples given at http://nodejs.org/api/dgram.html which worked for me in plain JavaScript.
So, how do I properly construct a buffer that I can send over my UDP socket?