mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-04 09:10:09 +00:00
Add typing for field
This commit is contained in:
28
field/field-test.ts
Normal file
28
field/field-test.ts
Normal 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
9
field/field.d.ts
vendored
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user