types for amp 0.3

This commit is contained in:
jewbre
2018-03-30 21:19:44 +02:00
parent 55a1b5699f
commit 635dd53a9d
4 changed files with 87 additions and 0 deletions

44
types/amp/amp-tests.ts Normal file
View File

@@ -0,0 +1,44 @@
import { decode, encode, Stream } from 'amp';
// $ExpectType Buffer[]
decode(new Buffer('something'));
// $ExpectType Buffer
encode([new Buffer('something'), new Buffer('something')]);
// $ExpectError
decode('');
// $ExpectError
decode(1);
// $ExpectError
decode();
// $ExpectError
encode('');
// $ExpectError
encode(1);
// $ExpectError
encode();
// $ExpectType Stream
new Stream({});
// $ExpectType Stream
new Stream({
highWaterMark: 1,
decodeStrings: true,
objectMode: true,
destroy: (error?: Error) => {
return 'handle error';
},
final: (callback: (error?: Error) => void) => {
// do nothing
}
});
// $ExpectError
new Stream({somethingNoneExisting: true});

19
types/amp/index.d.ts vendored Normal file
View File

@@ -0,0 +1,19 @@
// Type definitions for amp 0.3
// Project: https://github.com/visionmedia/node-amp
// Definitions by: Vilim Stubičan <https://github.com/jewbre>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="node" />
import * as stream from 'stream';
export function decode(buf: Buffer): Buffer[];
export function encode(args: Buffer[]): Buffer;
export class Stream extends stream.Writable {
constructor(opts: stream.WritableOptions);
_write(chunk: any, encoding: string, fn: () => void): void;
}

23
types/amp/tsconfig.json Normal file
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",
"amp-tests.ts"
]
}

1
types/amp/tslint.json Normal file
View File

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