[socketio-wildcard] introduce typings

This commit is contained in:
Dimitri Benin
2017-07-16 11:07:59 +02:00
parent ababb9cd46
commit 87972162a7
4 changed files with 62 additions and 0 deletions

15
types/socketio-wildcard/index.d.ts vendored Normal file
View File

@@ -0,0 +1,15 @@
// Type definitions for socketio-wildcard 2.0
// Project: https://github.com/hden/socketio-wildcard
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="socket.io" />
/// <reference types="socket.io-client" />
import EventEmitter = NodeJS.EventEmitter;
import Socket = SocketIO.Socket;
import ClientSocket = SocketIOClient.Socket;
export = sioWildcard;
declare function sioWildcard(emitterCtor?: { prototype: typeof EventEmitter.prototype }): (socket: Socket | ClientSocket, next?: (err?: any) => void) => void;

View File

@@ -0,0 +1,24 @@
import ioBuilder = require('socket.io');
const io = ioBuilder();
import middlewareBuilder = require('socketio-wildcard');
const middleware = middlewareBuilder();
io.use(middleware);
io.on('connection', (socket) => {
socket.on('*', (packet) => {
// client.emit('foo', 'bar', 'baz')
packet.data === ['foo', 'bar', 'baz'];
});
});
io.listen(8000);
import clientIo = require('socket.io-client');
const socket = clientIo('http://localhost');
import patchBuilder = require('socketio-wildcard');
const patch = patchBuilder(clientIo.Manager);
patch(socket);
socket.on('*', () => {
});

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"socketio-wildcard-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }