From 6916bab805ba6422454fc4f365660a687494fffd Mon Sep 17 00:00:00 2001 From: CaselIT Date: Mon, 10 Apr 2017 21:01:23 +0200 Subject: [PATCH 1/2] Added types for rwlock --- types/rwlock/index.d.ts | 36 ++++++++++++++++++++++++++++++++++++ types/rwlock/rwlock-tests.ts | 7 +++++++ types/rwlock/tsconfig.json | 22 ++++++++++++++++++++++ types/rwlock/tslint.json | 1 + 4 files changed, 66 insertions(+) create mode 100644 types/rwlock/index.d.ts create mode 100644 types/rwlock/rwlock-tests.ts create mode 100644 types/rwlock/tsconfig.json create mode 100644 types/rwlock/tslint.json diff --git a/types/rwlock/index.d.ts b/types/rwlock/index.d.ts new file mode 100644 index 0000000000..029c9d3d2b --- /dev/null +++ b/types/rwlock/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for RWLock v5.0.0 +// Project: https://github.com/71104/rwlock +// Definitions by: Federico Caselli +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class ReadWriteGeneric { + readLock(callback: T, options?: ReadWriteLock.Options): void; + readLock(key: string, callback: T, options?: ReadWriteLock.Options): void; + writeLock(callback: T, options?: ReadWriteLock.Options): void; + writeLock(key: string, callback: T, options?: ReadWriteLock.Options): void; +} +declare namespace ReadWriteLock { + interface Release { + (): void; + } + + interface Callback { + (release: Release): void; + } + + interface AsyncCallback { + (err: Error, release: Release): void; + } + + interface Options { + scope?: any; + timeout?: number; + timeoutCallback?: () => void; + } +} + +declare class ReadWriteLock extends ReadWriteGeneric{ + constructor(); + async: ReadWriteGeneric; +} +export = ReadWriteLock \ No newline at end of file diff --git a/types/rwlock/rwlock-tests.ts b/types/rwlock/rwlock-tests.ts new file mode 100644 index 0000000000..411733220b --- /dev/null +++ b/types/rwlock/rwlock-tests.ts @@ -0,0 +1,7 @@ +// Original test file https://github.com/71104/rwlock/blob/master/test/all.js +import * as ReadWriteLock from 'rwlock'; + +var lock = new ReadWriteLock(); +lock.readLock(function (release) { + release(); +}); diff --git a/types/rwlock/tsconfig.json b/types/rwlock/tsconfig.json new file mode 100644 index 0000000000..d5eefd893d --- /dev/null +++ b/types/rwlock/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rwlock-tests.ts" + ] +} \ No newline at end of file diff --git a/types/rwlock/tslint.json b/types/rwlock/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/types/rwlock/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From d052073bb9876836daf0c38006cccb581a9ded7a Mon Sep 17 00:00:00 2001 From: CaselIT Date: Mon, 10 Apr 2017 21:31:41 +0200 Subject: [PATCH 2/2] Fixed lint errors --- types/rwlock/index.d.ts | 18 ++++++------------ types/rwlock/rwlock-tests.ts | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/types/rwlock/index.d.ts b/types/rwlock/index.d.ts index 029c9d3d2b..a7611f22da 100644 --- a/types/rwlock/index.d.ts +++ b/types/rwlock/index.d.ts @@ -10,27 +10,21 @@ declare class ReadWriteGeneric { writeLock(key: string, callback: T, options?: ReadWriteLock.Options): void; } declare namespace ReadWriteLock { - interface Release { - (): void; - } + type Release = () => void; - interface Callback { - (release: Release): void; - } + type Callback = (release: Release) => void; - interface AsyncCallback { - (err: Error, release: Release): void; - } + type AsyncCallback = (err: Error, release: Release) => void; interface Options { scope?: any; timeout?: number; - timeoutCallback?: () => void; + timeoutCallback(): void; } } -declare class ReadWriteLock extends ReadWriteGeneric{ +declare class ReadWriteLock extends ReadWriteGeneric { constructor(); async: ReadWriteGeneric; } -export = ReadWriteLock \ No newline at end of file +export = ReadWriteLock; diff --git a/types/rwlock/rwlock-tests.ts b/types/rwlock/rwlock-tests.ts index 411733220b..8e2f210164 100644 --- a/types/rwlock/rwlock-tests.ts +++ b/types/rwlock/rwlock-tests.ts @@ -1,7 +1,7 @@ // Original test file https://github.com/71104/rwlock/blob/master/test/all.js import * as ReadWriteLock from 'rwlock'; -var lock = new ReadWriteLock(); -lock.readLock(function (release) { +const lock = new ReadWriteLock(); +lock.readLock((release) => { release(); });