From 41b75d423cd0d1bf3b2c025182846c17cf3e7eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vilim=20Stubi=C4=8Dan?= Date: Thu, 1 Mar 2018 23:29:57 +0100 Subject: [PATCH] Configurable type definitions (#24008) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Configurable type definitionsπ * Updated tests * Added tests for errorsπ * Updated project link * Changed definitions to the proposed structure --- types/configurable/configurable-tests.ts | 50 ++++++++++++++++++++++++ types/configurable/index.d.ts | 27 +++++++++++++ types/configurable/tsconfig.json | 23 +++++++++++ types/configurable/tslint.json | 1 + 4 files changed, 101 insertions(+) create mode 100644 types/configurable/configurable-tests.ts create mode 100644 types/configurable/index.d.ts create mode 100644 types/configurable/tsconfig.json create mode 100644 types/configurable/tslint.json diff --git a/types/configurable/configurable-tests.ts b/types/configurable/configurable-tests.ts new file mode 100644 index 0000000000..c718e53395 --- /dev/null +++ b/types/configurable/configurable-tests.ts @@ -0,0 +1,50 @@ +import configurable = require('configurable'); + +// Arrange +class A { + something(): void { + // nothing + } +} + +const obj = new A(); +const c = configurable(obj); + +// $ExpectType A & Configurable +c.set('first', 'first as a string'); + +// $ExpectType any +c.get('first'); + +// $ExpectType A & Configurable +c.enable('first'); + +// $ExpectType boolean +c.enabled('first'); + +// $ExpectType A & Configurable +c.disable('first'); + +// $ExpectType boolean +c.disabled('first'); + +// $ExpectError +c.set(5, 'first as a string'); + +// $ExpectError +c.set('first'); + +// $ExpectError +c.get(5); + +// $ExpectError +c.enable(5); + +// $ExpectError +c.enabled(5); + +// $ExpectError +c.disable(5); + +// $ExpectError +c.disabled(5); diff --git a/types/configurable/index.d.ts b/types/configurable/index.d.ts new file mode 100644 index 0000000000..470993e21a --- /dev/null +++ b/types/configurable/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for configurable 0.0 +// Project: https://www.npmjs.com/package/configurable +// Definitions by: Vilim Stubičan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +// Make any object configurable +declare function configurable(obj: T): T & Configurable; +export = configurable; + +interface Configurable { + settings: { + [key: string]: any; + }; + + set(name: string, val: any): T & Configurable; + + get(name: string): any; + + enable(name: string): T & Configurable; + + disable(name: string): T & Configurable; + + enabled(name: string): boolean; + + disabled(name: string): boolean; +} diff --git a/types/configurable/tsconfig.json b/types/configurable/tsconfig.json new file mode 100644 index 0000000000..2448b794e0 --- /dev/null +++ b/types/configurable/tsconfig.json @@ -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", + "configurable-tests.ts" + ] +} diff --git a/types/configurable/tslint.json b/types/configurable/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/configurable/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }