diff --git a/types/msgpack/index.d.ts b/types/msgpack/index.d.ts index 7d15442ce3..9d318641ae 100644 --- a/types/msgpack/index.d.ts +++ b/types/msgpack/index.d.ts @@ -3,81 +3,86 @@ // Definitions by: Shinya Mochizuki // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface MsgPackStatic { - /** - * @param data string or ByteArray. - * @param toString return string value if true. - * - * @return string or ByteArray or false. pack failed if false. - */ - pack(data: any, toString?: boolean): any; +declare namespace msgpack { + interface MsgPackStatic { + /** + * @param data string or ByteArray. + * @param toString return string value if true. + * + * @return string or ByteArray or false. pack failed if false. + */ + pack(data: any, toString?: boolean): any; - /** - * @param data string or ByteArray. - * - * @return string or ByteArray or undefined. unpack failed if undefined. - */ - unpack(data: any): any; + /** + * @param data string or ByteArray. + * + * @return string or ByteArray or undefined. unpack failed if undefined. + */ + unpack(data: any): any; - worker: string; + worker: string; - upload(url: string, option: MsgPackUploadOption, callback: MsgPackUploadCallback): void; + upload(url: string, option: MsgPackUploadOption, callback: MsgPackUploadCallback): void; - download(url: string, option: MsgPackDownloadOption, callback: MsgPackDownloadCallback): void; + download(url: string, option: MsgPackDownloadOption, callback: MsgPackDownloadCallback): void; + } + + interface MsgPackUploadOption { + /** + * string or ByteArray + */ + data: any; + + /** + * use WebWorker if true. + */ + worker?: boolean; + + /** + * timeout sec. + */ + timeout?: number; + + before?: (xhr: XMLHttpRequest, option: MsgPackUploadOption) => void; + + after?: (xhr: XMLHttpRequest, option: MsgPackUploadOption, result: MsgPackCallbackResult) => void; + } + + interface MsgPackUploadCallback { + (data: string, option: MsgPackUploadOption, result: MsgPackCallbackResult): void; + } + + interface MsgPackDownloadOption { + /** + * use WebWorker if true. + */ + worker?: boolean; + + /** + * timeout sec. + */ + timeout?: number; + + before?: (xhr: XMLHttpRequest, option: MsgPackDownloadOption) => void; + + after?: (xhr: XMLHttpRequest, option: MsgPackDownloadOption, result: MsgPackCallbackResult) => void; + } + + interface MsgPackDownloadCallback { + /** + * @param data string or ByteArray + */ + (data: any, option: MsgPackDownloadCallback, result: MsgPackCallbackResult): void; + } + + interface MsgPackCallbackResult { + status: number; + + ok: boolean; + } } -interface MsgPackUploadOption { - /** - * string or ByteArray - */ - data: any; +declare var msgpack: msgpack.MsgPackStatic; - /** - * use WebWorker if true. - */ - worker?: boolean; - - /** - * timeout sec. - */ - timeout?: number; - - before?: (xhr: XMLHttpRequest, option: MsgPackUploadOption) => void; - - after?: (xhr: XMLHttpRequest, option: MsgPackUploadOption, result: MsgPackCallbackResult) => void; -} - -interface MsgPackUploadCallback { - (data: string, option: MsgPackUploadOption, result: MsgPackCallbackResult): void; -} - -interface MsgPackDownloadOption { - /** - * use WebWorker if true. - */ - worker?: boolean; - - /** - * timeout sec. - */ - timeout?: number; - - before?: (xhr: XMLHttpRequest, option: MsgPackDownloadOption) => void; - - after?: (xhr: XMLHttpRequest, option: MsgPackDownloadOption, result: MsgPackCallbackResult) => void; -} - -interface MsgPackDownloadCallback { - /** - * @param data string or ByteArray - */ - (data: any, option: MsgPackDownloadCallback, result: MsgPackCallbackResult): void; -} - -interface MsgPackCallbackResult { - status: number; - - ok: boolean; -} - -declare var msgpack: MsgPackStatic; +export = msgpack; +export as namespace msgpack; diff --git a/types/msgpack/msgpack-tests.ts b/types/msgpack/msgpack-tests.ts index da0d12b926..b0b9a716a0 100644 --- a/types/msgpack/msgpack-tests.ts +++ b/types/msgpack/msgpack-tests.ts @@ -1,5 +1,3 @@ - - var packed = msgpack.pack(""); msgpack.unpack(packed); @@ -12,17 +10,17 @@ var uploadOption = { data: "", worker: false, timeout: 10, - before: (xhr: XMLHttpRequest, option: MsgPackUploadOption) => { }, - after: (xhr: XMLHttpRequest, option: MsgPackUploadOption, result: MsgPackCallbackResult) => { } + before: (xhr: XMLHttpRequest, option: msgpack.MsgPackUploadOption) => { }, + after: (xhr: XMLHttpRequest, option: msgpack.MsgPackUploadOption, result: msgpack.MsgPackCallbackResult) => { } }; -var uploadCallback = (data: string, option: MsgPackUploadOption, result: MsgPackCallbackResult) => { }; +var uploadCallback = (data: string, option: msgpack.MsgPackUploadOption, result: msgpack.MsgPackCallbackResult) => { }; msgpack.upload(url, uploadOption, uploadCallback); var downloadOption = { worker: false, timeout: 10, - before: (xhr: XMLHttpRequest, option: MsgPackDownloadOption) => { }, - after: (xhr: XMLHttpRequest, option: MsgPackDownloadOption, result: MsgPackCallbackResult) => { } + before: (xhr: XMLHttpRequest, option: msgpack.MsgPackDownloadOption) => { }, + after: (xhr: XMLHttpRequest, option: msgpack.MsgPackDownloadOption, result: msgpack.MsgPackCallbackResult) => { } }; -var downloadCallback = (data: any, option: MsgPackDownloadOption, result: MsgPackCallbackResult) => { }; +var downloadCallback = (data: any, option: msgpack.MsgPackDownloadOption, result: msgpack.MsgPackCallbackResult) => { }; msgpack.download(url, downloadOption, downloadCallback);