[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
This commit is contained in:
Rebecca Turner 2019-08-08 10:07:45 -07:00 committed by Nathan Shively-Sanders
parent 659898602e
commit 90298b1f8b
4 changed files with 65 additions and 0 deletions

21
types/pathval/index.d.ts vendored Normal file
View File

@ -0,0 +1,21 @@
// Type definitions for pathval 1.1
// Project: https://www.npmjs.com/package/pathval
// Definitions by: Rebecca Turner <https://github.com/9999years>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export interface PathInfo {
parent: object;
name: string;
value?: any;
exists: boolean;
}
export type Property = string | symbol | number;
export function hasProperty(obj: object | undefined | null, name: Property): boolean;
export function getPathInfo(obj: object, path: string): PathInfo;
export function getPathValue(obj: object, path: string): object | undefined;
export function setPathValue(obj: object, path: string, val: any): object;
export as namespace pathval;

View File

@ -0,0 +1,18 @@
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'

View File

@ -0,0 +1,23 @@
{
"files": [
"index.d.ts",
"pathval-tests.ts"
],
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}

View File

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