diff --git a/src/types.ts b/src/types.ts index 7227386..09cb5a4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -35,7 +35,7 @@ export type StrictSchema = { /** `destinationProperty` is the name of the property of the target object you want to produce */ [destinationProperty in keyof Target]: | ActionString - | ActionFunction + | { (iteratee: Source, source: Source[], target: Target[destinationProperty]): Target[destinationProperty] } | ActionAggregator | ActionSelector | StrictSchema; @@ -44,7 +44,7 @@ export type Schema = { /** `destinationProperty` is the name of the property of the target object you want to produce */ [destinationProperty in keyof Target]?: | ActionString - | ActionFunction + | { (iteratee: Source, source: Source[], target: Target[destinationProperty]): Target[destinationProperty] } | ActionAggregator | ActionSelector | Schema; diff --git a/src/typescript.spec.ts b/src/typescript.spec.ts index daccd97..129eac4 100644 --- a/src/typescript.spec.ts +++ b/src/typescript.spec.ts @@ -1,4 +1,4 @@ -import Morphism, { morphism, StrictSchema, Schema } from './morphism'; +import Morphism, { morphism, StrictSchema, Schema, createSchema } from './morphism'; describe('Typescript', () => { describe('Registry Type Checking', () => { @@ -184,6 +184,14 @@ describe('Typescript', () => { expect(item).toEqual(expected[idx]); }); }); + + it('should accept union types as Target', () => { + const schema = createSchema<{ a: string } | { a: string; b: string }, { c: string }>({ + a: ({ c }) => c + }); + + expect(morphism(schema, { c: 'result' }).a).toEqual('result'); + }); }); describe('Morphism Function Type Checking', () => {