Add typing for field

This commit is contained in:
Leo Liang
2016-01-04 15:41:48 +08:00
parent dc9dabe74a
commit d75d2c9629
2 changed files with 37 additions and 0 deletions

28
field/field-test.ts Normal file
View File

@@ -0,0 +1,28 @@
// From https://github.com/jprichardson/field/blob/e968fd979ba1a06e35571695ddfdad513e516eae/README.md
/// <reference path="field.d.ts" />
// get
const config = {
environment: {
production: {
port: 80
}
}
}
console.log(field.get(config, 'environment:production:port'))
// => 80
// set
var database: any = {}
console.log(field.get(database, 'production.port'))
// => undefined
// will return undefined since it never existed before
field.set(database, 'production.port', 27017)
console.log(database.production.port)
// => 27017

9
field/field.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
// Type definitions for field 1.0.1
// Project: https://www.npmjs.com/package/field
// Definitions by: Leo Liang <https://github.com/aleung/DefinitelyTyped>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module field {
export function get(topObj: any, fields: string): any;
export function set(topObj: any, fields: string, value: any): any;
}