diff --git a/types/conf/conf-tests.ts b/types/conf/conf-tests.ts index 1da0e4de2d..ce67cd4799 100644 --- a/types/conf/conf-tests.ts +++ b/types/conf/conf-tests.ts @@ -4,18 +4,24 @@ const conf = new Conf(); new Conf({ defaults: { foo: 'bar', - unicorn: 'rainbow' + unicorn: 'rainbow', }, - configName: '', - projectName: 'foo', - cwd: '' }); +new Conf({ configName: '' }); +new Conf({ projectName: 'foo' }); +new Conf({ cwd: '' }); +new Conf({ encryptionKey: '' }); +new Conf({ encryptionKey: new Buffer('') }); +new Conf({ encryptionKey: new Uint8Array([1]) }); +new Conf({ encryptionKey: new DataView(new ArrayBuffer(2)) }); +new Conf({ fileExtension: '.foo' }); + // $ExpectError new Conf({ defaults: { foo: 'bar', - unicorn: ['rainbow'] - } + unicorn: ['rainbow'], + }, }); conf.set('foo', 'bar'); conf.set('hello', 1); @@ -28,10 +34,17 @@ conf.get('foo', null); // $ExpectError conf.delete('foo'); conf.has('foo'); // $ExpectType boolean conf.clear(); +conf.onDidChange('foo', (oldVal, newVal) => { + // $ExpectType string | number | boolean | undefined + oldVal; + // $ExpectType string | number | boolean | undefined + newVal; +}); +conf.size; // $ExpectType number conf.store = { foo: 'bar', - unicorn: 'rainbow' + unicorn: 'rainbow', }; conf.path; // $ExpectType string diff --git a/types/conf/index.d.ts b/types/conf/index.d.ts index e58dc3ede7..57d7285a3e 100644 --- a/types/conf/index.d.ts +++ b/types/conf/index.d.ts @@ -1,31 +1,37 @@ -// Type definitions for conf 1.4 +// Type definitions for conf 2.1 // Project: https://github.com/sindresorhus/conf // Definitions by: Sam Verschueren // BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -interface Options { - defaults?: {[key: string]: T}; - configName?: string; - projectName?: string; - cwd?: string; -} +/// declare class Conf implements Iterable<[string, T]> { - store: {[key: string]: T}; + store: { [key: string]: T }; readonly path: string; - readonly size: number; + readonly size: number; - constructor(options?: Options); - get(key: string, defaultValue?: T): T; - set(key: string, val: T): void; - set(object: {[key: string]: T}): void; - has(key: string): boolean; - delete(key: string): void; - clear(): void; - onDidChange(key: string, callback: (oldVal: any, newVal: any) => void): void; - [Symbol.iterator](): Iterator<[string, T]>; + constructor(options?: Conf.Options); + get(key: string, defaultValue?: T): T; + set(key: string, val: T): void; + set(object: { [key: string]: T }): void; + has(key: string): boolean; + delete(key: string): void; + clear(): void; + onDidChange(key: string, callback: (oldVal: T | undefined, newVal: T | undefined) => void): void; + [Symbol.iterator](): Iterator<[string, T]>; +} + +declare namespace Conf { + interface Options { + defaults?: { [key: string]: T }; + configName?: string; + projectName?: string; + cwd?: string; + encryptionKey?: string | Buffer | NodeJS.TypedArray | DataView; + fileExtension?: string; + } } export = Conf; diff --git a/types/conf/tsconfig.json b/types/conf/tsconfig.json index 84d6bf7657..479fa6b41f 100644 --- a/types/conf/tsconfig.json +++ b/types/conf/tsconfig.json @@ -21,4 +21,4 @@ "index.d.ts", "conf-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/conf/v1/conf-tests.ts b/types/conf/v1/conf-tests.ts new file mode 100644 index 0000000000..4ee492da8d --- /dev/null +++ b/types/conf/v1/conf-tests.ts @@ -0,0 +1,41 @@ +import Conf = require('conf'); + +const conf = new Conf(); +new Conf({ + defaults: { + foo: 'bar', + unicorn: 'rainbow', + }, + configName: '', + projectName: 'foo', + cwd: '', +}); +// $ExpectError +new Conf({ + defaults: { + foo: 'bar', + unicorn: ['rainbow'], + }, +}); +conf.set('foo', 'bar'); +conf.set('hello', 1); +conf.set('unicorn', false); +conf.set('null', null); // $ExpectError + +conf.get('foo'); // $ExpectType string | number | boolean +conf.get('foo', 'bar'); // $ExpectType string | number | boolean +conf.get('foo', null); // $ExpectError +conf.delete('foo'); +conf.has('foo'); // $ExpectType boolean +conf.clear(); + +conf.store = { + foo: 'bar', + unicorn: 'rainbow', +}; +conf.path; // $ExpectType string + +for (const [key, value] of conf) { + key; // $ExpectType string + value; // $ExpectType string | number | boolean +} diff --git a/types/conf/v1/index.d.ts b/types/conf/v1/index.d.ts new file mode 100644 index 0000000000..f08cff1584 --- /dev/null +++ b/types/conf/v1/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for conf 1.4 +// Project: https://github.com/sindresorhus/conf +// Definitions by: Sam Verschueren +// BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +interface Options { + defaults?: { [key: string]: T }; + configName?: string; + projectName?: string; + cwd?: string; +} + +declare class Conf implements Iterable<[string, T]> { + store: { [key: string]: T }; + readonly path: string; + readonly size: number; + + constructor(options?: Options); + get(key: string, defaultValue?: T): T; + set(key: string, val: T): void; + set(object: { [key: string]: T }): void; + has(key: string): boolean; + delete(key: string): void; + clear(): void; + onDidChange(key: string, callback: (oldVal: any, newVal: any) => void): void; + [Symbol.iterator](): Iterator<[string, T]>; +} + +export = Conf; diff --git a/types/conf/v1/tsconfig.json b/types/conf/v1/tsconfig.json new file mode 100644 index 0000000000..86b3a62f41 --- /dev/null +++ b/types/conf/v1/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "conf": [ + "conf/v1" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "conf-tests.ts" + ] +} diff --git a/types/conf/v1/tslint.json b/types/conf/v1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/conf/v1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }