mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-20 00:59:29 +08:00
feat(types): Add typings for "multistream" package
This commit is contained in:
20
types/multistream/index.d.ts
vendored
Normal file
20
types/multistream/index.d.ts
vendored
Normal 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;
|
||||
40
types/multistream/multistream-tests.ts
Normal file
40
types/multistream/multistream-tests.ts
Normal 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]);
|
||||
23
types/multistream/tsconfig.json
Normal file
23
types/multistream/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/multistream/tslint.json
Normal file
1
types/multistream/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user