feat(types): Add typings for "multistream" package

This commit is contained in:
Denis Malinochkin
2017-11-13 10:03:06 +03:00
parent 8ca6a6e423
commit 2e736e09cc
4 changed files with 84 additions and 0 deletions

20
types/multistream/index.d.ts vendored Normal file
View File

@@ -0,0 +1,20 @@
// Type definitions for multistream 2.1
// Project: https://github.com/feross/multistream
// Definitions by: mrmlnc <https://github.com/mrmlnc>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { Stream } from 'stream';
declare function multistream(streams: multistream.Streams): NodeJS.ReadableStream;
declare namespace multistream {
type LazyStream = () => Stream;
type FactoryStream = (cb: (err: Error | null, stream: NodeJS.ReadableStream) => any) => void;
type Streams = Array<LazyStream | NodeJS.ReadableStream> | FactoryStream;
function obj(streams: Streams): NodeJS.ReadableStream;
}
export = multistream;

View File

@@ -0,0 +1,40 @@
import fs = require('fs');
import stream = require('stream');
import through = require('through');
import through2 = require('through2');
import multistream = require('multistream');
const readable = new stream.Readable();
const writable = new stream.Writable();
const transform = new stream.Transform();
const duplex = new stream.Duplex();
const pass = new stream.PassThrough();
const streams = [
readable,
transform,
duplex,
pass,
through(),
through2(),
fs.createReadStream('.filepath'),
() => fs.createWriteStream('.filepath2')
];
const factory: multistream.FactoryStream = (cb) => {
if (1 === 1) return cb(null, fs.createReadStream('.filepath'));
cb(null, fs.createReadStream('.filepath'));
};
// $ExpectType ReadableStream
multistream(streams);
multistream(factory);
// $ExpectType ReadableStream
multistream.obj(streams);
multistream.obj(factory);
// $ExpectError
multistream([writable]);

View File

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

View File

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