Skip to content

Not able to map complex object using StrictSchema #50

@nitin786786

Description

@nitin786786

I am trying to implement morphism/DTO mapping concept in typescript.

I am trying to do source to destination mapping of a complex type object (i.e an object containing another object and arrays of object) in generic way using StrictSchema of morphism.

my interface is :

			interface IFoo {  
				  keyA: {
				  key1: number,
				  key2: number,
				  key3: [
					{
					  key3A: string,
					  key3B: number
					}
				  ],
				  key4: string
				},
				keyB: string,
				keyC: number,
				keyD: {
				  key1: string,
				  key2: {
					key2A: string
				  },
				  key3: string
				},
				keyE: string
			}


			const schema: StrictSchema<IFoo> = 
			{  keyA: {
				  key1: 'somepath',
				  key2: 'somepath',
				  key3: [
					{
					  key3A: 'somepath',
					  key3B: 'somepath'
					}
				  ],
				  key4: 'somepath'
				},
				keyB: 'somepath',
				keyC: 'somepath',
				keyD: {
				  key1: 'somepath',
				  key2: {
					key2A: 'somepath'
				  },
				  key3: 'somepath'
				},
				keyE: 'somepath'
			};

		const target = morphism(schema, someSourceObject);

Here, schema is the object-preserving map for my interface. I have added 'somepath' as a value for each key and I will replace this with some actual path from the actual source object.
but while doing so I am getting:

Error : The expected type comes from property 'keyA' which is declared here on type 'StrictSchema<IFoo, any>

So, First of all, can I preserve mapping in above scenarieo using morphism because I have not come accross any such examples using 'ScrictSchema'. If yes, then how?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions