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" }