mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Add types for object-mapper (#42495)
This commit is contained in:
Vendored
+7
@@ -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);
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user