mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Update types for conf to v2.1
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import Conf = require('conf');
|
||||
|
||||
const conf = new Conf<string | number | boolean>();
|
||||
new Conf<string>({
|
||||
defaults: {
|
||||
foo: 'bar',
|
||||
unicorn: 'rainbow',
|
||||
},
|
||||
});
|
||||
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'],
|
||||
},
|
||||
});
|
||||
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.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',
|
||||
};
|
||||
conf.path; // $ExpectType string
|
||||
|
||||
for (const [key, value] of conf) {
|
||||
key; // $ExpectType string
|
||||
value; // $ExpectType string | number | boolean
|
||||
}
|
||||
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
// 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
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
declare class Conf<T = any> implements Iterable<[string, T]> {
|
||||
store: { [key: string]: T };
|
||||
readonly path: string;
|
||||
readonly size: number;
|
||||
|
||||
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;
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"conf-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+15
-15
@@ -6,26 +6,26 @@
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
interface Options<T> {
|
||||
defaults?: {[key: string]: T};
|
||||
configName?: string;
|
||||
projectName?: string;
|
||||
cwd?: string;
|
||||
defaults?: { [key: string]: T };
|
||||
configName?: string;
|
||||
projectName?: string;
|
||||
cwd?: string;
|
||||
}
|
||||
|
||||
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?: 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;
|
||||
|
||||
Reference in New Issue
Block a user