add redis-error types

This commit is contained in:
43081j 2017-12-01 16:47:50 +00:00
parent b4855506d3
commit df277f8016
4 changed files with 84 additions and 0 deletions

33
types/redis-errors/index.d.ts vendored Normal file
View File

@ -0,0 +1,33 @@
// Type definitions for redis-errors 1.2
// Project: https://github.com/NodeRedis/redis-errors#readme
// Definitions by: James Garbutt <https://github.com/43081j>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export class RedisError extends Error {
}
export class ParserError extends RedisError {
buffer: string;
offset: number;
constructor(message: string, buffer: string, offset: number);
}
export class ReplyError extends RedisError {
command?: string;
args?: any[];
code?: string;
constructor(message: string);
}
export class AbortError extends RedisError {
command?: string;
args?: any[];
}
export class InterruptError extends RedisError {
command?: string;
args?: any[];
origin: Error;
}

View File

@ -0,0 +1,27 @@
import {
RedisError,
ReplyError,
ParserError,
AbortError,
InterruptError
} from 'redis-errors';
const err = new RedisError('some error');
const reply = new ReplyError('some error');
const replyArgs: any[] | undefined = reply.args;
const replyCommand: string | undefined = reply.command;
const replyCode: string | undefined = reply.code;
const parser = new ParserError('some error', 'a buffer', 4);
const parserBuffer: string = parser.buffer;
const parserOffset: number = parser.offset;
const abort = new AbortError('some error');
const abortArgs: any[] | undefined = abort.args;
const abortCommand: string | undefined = abort.command;
const interrupt = new InterruptError('some error');
const interruptArgs: any[] | undefined = interrupt.args;
const interruptCommand: string | undefined = interrupt.command;
const interruptOrigin: Error | undefined = interrupt.origin;

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",
"redis-errors-tests.ts"
]
}

View File

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