mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Configurable type definitions (#24008)
* Configurable type definitionsπ * Updated tests * Added tests for errorsπ * Updated project link * Changed definitions to the proposed structure
This commit is contained in:
committed by
Mohamed Hegazy
parent
82b9044020
commit
41b75d423c
50
types/configurable/configurable-tests.ts
Normal file
50
types/configurable/configurable-tests.ts
Normal file
@@ -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<A>
|
||||
c.set('first', 'first as a string');
|
||||
|
||||
// $ExpectType any
|
||||
c.get('first');
|
||||
|
||||
// $ExpectType A & Configurable<A>
|
||||
c.enable('first');
|
||||
|
||||
// $ExpectType boolean
|
||||
c.enabled('first');
|
||||
|
||||
// $ExpectType A & Configurable<A>
|
||||
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);
|
||||
27
types/configurable/index.d.ts
vendored
Normal file
27
types/configurable/index.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Type definitions for configurable 0.0
|
||||
// Project: https://www.npmjs.com/package/configurable
|
||||
// Definitions by: Vilim Stubičan <https://github.com/jewbre>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
// Make any object configurable
|
||||
declare function configurable<T extends object>(obj: T): T & Configurable<T>;
|
||||
export = configurable;
|
||||
|
||||
interface Configurable<T> {
|
||||
settings: {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
set(name: string, val: any): T & Configurable<T>;
|
||||
|
||||
get(name: string): any;
|
||||
|
||||
enable(name: string): T & Configurable<T>;
|
||||
|
||||
disable(name: string): T & Configurable<T>;
|
||||
|
||||
enabled(name: string): boolean;
|
||||
|
||||
disabled(name: string): boolean;
|
||||
}
|
||||
23
types/configurable/tsconfig.json
Normal file
23
types/configurable/tsconfig.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
1
types/configurable/tslint.json
Normal file
1
types/configurable/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user