diff --git a/types/multistream/index.d.ts b/types/multistream/index.d.ts new file mode 100644 index 0000000000..7a7d0eb309 --- /dev/null +++ b/types/multistream/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for multistream 2.1 +// Project: https://github.com/feross/multistream +// Definitions by: mrmlnc +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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 | FactoryStream; + + function obj(streams: Streams): NodeJS.ReadableStream; +} + +export = multistream; diff --git a/types/multistream/multistream-tests.ts b/types/multistream/multistream-tests.ts new file mode 100644 index 0000000000..99206e0102 --- /dev/null +++ b/types/multistream/multistream-tests.ts @@ -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]); diff --git a/types/multistream/tsconfig.json b/types/multistream/tsconfig.json new file mode 100644 index 0000000000..3fa5cc7c47 --- /dev/null +++ b/types/multistream/tsconfig.json @@ -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" + ] +} diff --git a/types/multistream/tslint.json b/types/multistream/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/multistream/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }