From e16ce4a79a83a6c31e90c8661903dc2c36ae511d Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sat, 19 Dec 2015 03:25:03 +0100 Subject: [PATCH] export HttpError thanks to a namespace --- http-errors/http-errors-tests.ts | 2 + http-errors/http-errors.d.ts | 156 ++++++++++++++++--------------- 2 files changed, 82 insertions(+), 76 deletions(-) diff --git a/http-errors/http-errors-tests.ts b/http-errors/http-errors-tests.ts index 9ee89d6a6..440325900 100644 --- a/http-errors/http-errors-tests.ts +++ b/http-errors/http-errors-tests.ts @@ -67,3 +67,5 @@ var err = new createError['404'](); //createError['404'](); // TypeScript should fail with "Did you mean to include 'new'?" //new createError(); // TypeScript should fail with "Only a void function can be called with the 'new' keyword" + +let error: createError.HttpError; diff --git a/http-errors/http-errors.d.ts b/http-errors/http-errors.d.ts index 6f78ff6a7..e15a7cb4e 100644 --- a/http-errors/http-errors.d.ts +++ b/http-errors/http-errors.d.ts @@ -4,82 +4,86 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module 'http-errors' { - interface HttpError extends Error { - status: number; - statusCode: number; - expose: boolean; + namespace createHttpError { + + // See https://github.com/jshttp/http-errors/blob/1.3.1/index.js#L42 + interface HttpError extends Error { + status: number; + statusCode: number; + expose: boolean; + } + + interface CreateHttpError { + // See https://github.com/Microsoft/TypeScript/issues/227#issuecomment-50092674 + [code: string]: new() => HttpError; + + (...args: Array): HttpError; + + Continue: new() => HttpError; + SwitchingProtocols: new() => HttpError; + Processing: new() => HttpError; + OK: new() => HttpError; + Created: new() => HttpError; + Accepted: new() => HttpError; + NonAuthoritativeInformation: new() => HttpError; + NoContent: new() => HttpError; + ResetContent: new() => HttpError; + PartialContent: new() => HttpError; + MultiStatus: new() => HttpError; + AlreadyReported: new() => HttpError; + IMUsed: new() => HttpError; + MultipleChoices: new() => HttpError; + MovedPermanently: new() => HttpError; + Found: new() => HttpError; + SeeOther: new() => HttpError; + NotModified: new() => HttpError; + UseProxy: new() => HttpError; + Unused: new() => HttpError; + TemporaryRedirect: new() => HttpError; + PermanentRedirect: new() => HttpError; + BadRequest: new() => HttpError; + Unauthorized: new() => HttpError; + PaymentRequired: new() => HttpError; + Forbidden: new() => HttpError; + NotFound: new() => HttpError; + MethodNotAllowed: new() => HttpError; + NotAcceptable: new() => HttpError; + ProxyAuthenticationRequired: new() => HttpError; + RequestTimeout: new() => HttpError; + Conflict: new() => HttpError; + Gone: new() => HttpError; + LengthRequired: new() => HttpError; + PreconditionFailed: new() => HttpError; + PayloadTooLarge: new() => HttpError; + URITooLong: new() => HttpError; + UnsupportedMediaType: new() => HttpError; + RangeNotSatisfiable: new() => HttpError; + ExpectationFailed: new() => HttpError; + ImATeapot: new() => HttpError; + UnprocessableEntity: new() => HttpError; + Locked: new() => HttpError; + FailedDependency: new() => HttpError; + UnorderedCollection: new() => HttpError; + UpgradeRequired: new() => HttpError; + PreconditionRequired: new() => HttpError; + TooManyRequests: new() => HttpError; + RequestHeaderFieldsTooLarge: new() => HttpError; + UnavailableForLegalReasons: new() => HttpError; + InternalServerError: new() => HttpError; + NotImplemented: new() => HttpError; + BadGateway: new() => HttpError; + ServiceUnavailable: new() => HttpError; + GatewayTimeout: new() => HttpError; + HTTPVersionNotSupported: new() => HttpError; + VariantAlsoNegotiates: new() => HttpError; + InsufficientStorage: new() => HttpError; + LoopDetected: new() => HttpError; + BandwidthLimitExceeded: new() => HttpError; + NotExtended: new() => HttpError; + NetworkAuthenticationRequired: new() => HttpError; + } } - interface CreateHttpError { - // See https://github.com/Microsoft/TypeScript/issues/227#issuecomment-50092674 - [code: string]: new() => HttpError; - - (...args: Array): HttpError; - - Continue: new() => HttpError; - SwitchingProtocols: new() => HttpError; - Processing: new() => HttpError; - OK: new() => HttpError; - Created: new() => HttpError; - Accepted: new() => HttpError; - NonAuthoritativeInformation: new() => HttpError; - NoContent: new() => HttpError; - ResetContent: new() => HttpError; - PartialContent: new() => HttpError; - MultiStatus: new() => HttpError; - AlreadyReported: new() => HttpError; - IMUsed: new() => HttpError; - MultipleChoices: new() => HttpError; - MovedPermanently: new() => HttpError; - Found: new() => HttpError; - SeeOther: new() => HttpError; - NotModified: new() => HttpError; - UseProxy: new() => HttpError; - Unused: new() => HttpError; - TemporaryRedirect: new() => HttpError; - PermanentRedirect: new() => HttpError; - BadRequest: new() => HttpError; - Unauthorized: new() => HttpError; - PaymentRequired: new() => HttpError; - Forbidden: new() => HttpError; - NotFound: new() => HttpError; - MethodNotAllowed: new() => HttpError; - NotAcceptable: new() => HttpError; - ProxyAuthenticationRequired: new() => HttpError; - RequestTimeout: new() => HttpError; - Conflict: new() => HttpError; - Gone: new() => HttpError; - LengthRequired: new() => HttpError; - PreconditionFailed: new() => HttpError; - PayloadTooLarge: new() => HttpError; - URITooLong: new() => HttpError; - UnsupportedMediaType: new() => HttpError; - RangeNotSatisfiable: new() => HttpError; - ExpectationFailed: new() => HttpError; - ImATeapot: new() => HttpError; - UnprocessableEntity: new() => HttpError; - Locked: new() => HttpError; - FailedDependency: new() => HttpError; - UnorderedCollection: new() => HttpError; - UpgradeRequired: new() => HttpError; - PreconditionRequired: new() => HttpError; - TooManyRequests: new() => HttpError; - RequestHeaderFieldsTooLarge: new() => HttpError; - UnavailableForLegalReasons: new() => HttpError; - InternalServerError: new() => HttpError; - NotImplemented: new() => HttpError; - BadGateway: new() => HttpError; - ServiceUnavailable: new() => HttpError; - GatewayTimeout: new() => HttpError; - HTTPVersionNotSupported: new() => HttpError; - VariantAlsoNegotiates: new() => HttpError; - InsufficientStorage: new() => HttpError; - LoopDetected: new() => HttpError; - BandwidthLimitExceeded: new() => HttpError; - NotExtended: new() => HttpError; - NetworkAuthenticationRequired: new() => HttpError; - } - - var httpError: CreateHttpError; - export = httpError; + var createHttpError: createHttpError.CreateHttpError; + export = createHttpError; }