DefinitelyTyped/types/pathval/pathval-tests.ts
Rebecca Turner 90298b1f8b [pathval] Add types for pathval (#37453)
* [pathval] Add types for pathval

* Clean up redundant interfaces, use UMD mod. syntax

Changes requested by @sandersn

- Don't override lint rules in tslint.json
- Use modern UMD module syntax
- Removed redundant namespaces
2019-08-08 10:07:45 -07:00

19 lines
500 B
TypeScript

import * as pathval from 'pathval';
const obj = { prop: 'a value' };
pathval.hasProperty(obj, 'prop'); // true
const earth = { earth: { country: 'Brazil' } };
pathval.getPathInfo(earth, 'earth.country');
const info: pathval.PathInfo = {
parent: { country: 'Brazil' },
name: 'country',
value: 'Brazil',
exists: true,
};
pathval.getPathValue(earth, 'earth.country'); // 'Brazil'
pathval.setPathValue(earth, 'earth.country', 'USA');
const usa: string = earth.earth.country; // 'USA'