Add typings for settings module.

This commit is contained in:
shrey 2018-03-03 10:11:00 -05:00
parent 420e0d5d29
commit aaafc25a53
4 changed files with 89 additions and 0 deletions

30
types/settings/index.d.ts vendored Normal file
View File

@ -0,0 +1,30 @@
// Type definitions for settings 0.1
// Project: https://github.com/mgutz/node-settings
// Definitions by: Shrey Jain <https://github.com/shreyjain1994>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// This wierd looking class definition is necessary since the function that the module
// exposes NEEDS (will throw error otherwise) to be called with the `new` keyword
// BUT returns a random object...not an instance of the class
declare class Settings {
constructor(pathOrModule: Settings.PathOrModule, options?: Settings.Options);
[setting: string]: any;
}
declare namespace Settings {
interface Options {
env?: string;
root?: string;
defaults?: any;
}
type PathOrModule = string |
{
forceEnv?: string,
common: any, // error is thrown if 'common' object is not provided
[envName: string]: any
};
}
export = Settings;

View File

@ -0,0 +1,33 @@
import Settings = require('settings');
// works without options
new Settings('foo');
// works with path to module containing settings
const settings = new Settings('./path/to/my/config');
// any prop is accessible on returned value
settings.hello = 'world';
const foo = settings.bar;
// works with settings object
const settings2 = new Settings({
common: {setting: 'mySetting'}, production: {
hello: 'bar'
}
});
settings2.hello = 'world';
// allows for forceEnv in settings object
const settings3 = new Settings({
common: {},
forceEnv: 'production'
});
// allows options
const settings4 = new Settings('./path/to/my/settings', {
root: 'someRoot',
env: 'development',
defaults: {
someSetting: 'settingValue'
}
});

View 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",
"settings-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}