Add types for object-mapper (#42495)

This commit is contained in:
Ryan Fahsel
2020-02-19 17:31:20 -08:00
committed by GitHub
parent 75ad8d682d
commit f56a1c3594
4 changed files with 76 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
// Type definitions for object-mapper 6.2
// Project: https://github.com/wankdanker/node-object-mapper#readme
// Definitions by: Ryan Fahsel <https://github.com/me>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export function merge(srcObject: object, mapObject: object): object;
export function merge<T>(srcObject: object, destinationObject: T, mapObject: object): T;
@@ -0,0 +1,45 @@
import { merge } from 'object-mapper';
interface FlatPerson {
name: string;
age: number;
mother: string;
father: string;
}
interface Family {
father: string;
mother: string;
}
interface NestedPerson {
name: string;
age: number;
family: Family;
}
const mapping = {
name: 'name',
age: 'age',
mother: 'family.mother',
father: 'family.father',
};
const nestedPerson: NestedPerson = {
name: 'Jack Bauer',
age: 29,
family: {
father: 'Mike',
mother: 'Christina',
},
};
const flatPerson: FlatPerson = {
name: 'Value that will be replaced',
age: -2,
father: 'Value that will be replaced',
mother: 'Value that will be replaced',
};
merge(nestedPerson, mapping);
merge(nestedPerson, flatPerson, mapping);
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"object-mapper-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }