Added actual type definition and tests

This commit is contained in:
IanStorm
2018-11-19 20:34:19 +01:00
parent 4b09a1e100
commit 1074143fd8
2 changed files with 55 additions and 29 deletions
+18 -29
View File
@@ -3,37 +3,26 @@
// Definitions by: IanStorm <https://github.com/IanStorm>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/*~ If this module is a UMD module that exposes a global variable 'myLib' when
*~ loaded outside a module loader environment, declare that global here.
*~ Otherwise, delete this declaration.
*/
export as namespace myLib;
/// <reference types="node" />
/*~ If this module has methods, declare them as functions like so.
*/
export function myMethod(a: string): string;
export function myOtherMethod(a: number): number;
/*~ You can declare types that are available via importing the module */
export interface someType {
name: string;
length: number;
extras?: string[];
import { Duplex, DuplexOptions } from "stream";
declare namespace ListStream {
}
/*~ You can declare properties of the module using const, let, or var */
export const myField: number;
declare class ListStream extends Duplex {
constructor(callback?: (err: Error, data: any[]) => void);
constructor(options?: DuplexOptions, callback?: (err: Error, data: any[]) => void);
/*~ If there are types, properties, or methods inside dotted names
*~ of the module, declare them inside a 'namespace'.
*/
export namespace subProp {
/*~ For example, given this definition, someone could write:
*~ import { subProp } from 'yourModule';
*~ subProp.foo();
*~ or
*~ import * as yourMod from 'yourModule';
*~ yourMod.subProp.foo();
*/
export function foo(): void;
}
static obj(callback?: (err: Error, data: any[]) => void): ListStream;
static obj(options?: DuplexOptions, callback?: (err: Error, data: any[]) => void): ListStream;
append(chunk: any): void;
duplicate(): ListStream;
end(): void;
get(index: number): any;
length: number;
}
export = ListStream;
+37
View File
@@ -0,0 +1,37 @@
import * as ListStream from "list-stream";
let chunk: any = "chunk";
let listStream: ListStream;
let num: number = 1;
listStream = new ListStream((err: Error, data: any[]) => {
if (err) { throw err; }
console.log(data.length);
for (const date of data) {
console.log(date);
}
});
listStream = new ListStream({ objectMode: true }, (err: Error, data: any[]) => {
if (err) { throw err; }
console.log(data.length);
for (const date of data) {
console.log(date);
}
});
listStream = ListStream.obj((err: Error, data: any[]) => {
if (err) { throw err; }
console.log(data.length);
for (const date of data) {
console.log(date);
}
});
listStream.append(chunk);
listStream = listStream.duplicate();
listStream.end();
chunk = listStream.get(num);
num = listStream.length;