Merge pull request #31285 from BendingBender/conf

Update types for conf to v2.1
This commit is contained in:
Jesse Trinity
2018-12-13 16:09:37 -08:00
committed by GitHub
7 changed files with 147 additions and 26 deletions
+20 -7
View File
@@ -4,18 +4,24 @@ const conf = new Conf<string | number | boolean>();
new Conf<string>({
defaults: {
foo: 'bar',
unicorn: 'rainbow'
unicorn: 'rainbow',
},
configName: '',
projectName: 'foo',
cwd: ''
});
new Conf<string>({ configName: '' });
new Conf<string>({ projectName: 'foo' });
new Conf<string>({ cwd: '' });
new Conf<string>({ encryptionKey: '' });
new Conf<string>({ encryptionKey: new Buffer('') });
new Conf<string>({ encryptionKey: new Uint8Array([1]) });
new Conf<string>({ encryptionKey: new DataView(new ArrayBuffer(2)) });
new Conf<string>({ fileExtension: '.foo' });
// $ExpectError
new Conf<string>({
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
+24 -18
View File
@@ -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 <https://github.com/SamVerschueren>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
interface Options<T> {
defaults?: {[key: string]: T};
configName?: string;
projectName?: string;
cwd?: string;
}
/// <reference types="node" />
declare class Conf<T = any> implements Iterable<[string, T]> {
store: {[key: string]: T};
store: { [key: string]: T };
readonly path: string;
readonly size: number;
readonly size: number;
constructor(options?: Options<T>);
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<T>);
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<T> {
defaults?: { [key: string]: T };
configName?: string;
projectName?: string;
cwd?: string;
encryptionKey?: string | Buffer | NodeJS.TypedArray | DataView;
fileExtension?: string;
}
}
export = Conf;
+1 -1
View File
@@ -21,4 +21,4 @@
"index.d.ts",
"conf-tests.ts"
]
}
}
+41
View File
@@ -0,0 +1,41 @@
import Conf = require('conf');
const conf = new Conf<string | number | boolean>();
new Conf<string>({
defaults: {
foo: 'bar',
unicorn: 'rainbow',
},
configName: '',
projectName: 'foo',
cwd: '',
});
// $ExpectError
new Conf<string>({
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
}
+31
View File
@@ -0,0 +1,31 @@
// Type definitions for conf 1.4
// Project: https://github.com/sindresorhus/conf
// Definitions by: Sam Verschueren <https://github.com/SamVerschueren>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
interface Options<T> {
defaults?: { [key: string]: T };
configName?: string;
projectName?: string;
cwd?: string;
}
declare class Conf<T = any> implements Iterable<[string, T]> {
store: { [key: string]: T };
readonly path: string;
readonly size: number;
constructor(options?: Options<T>);
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;
+29
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }