Skip to content

Commit

Permalink
fix: signature when items are null with type to get a mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
emyann committed Mar 17, 2019
1 parent 05a1a30 commit 44b8ca2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/morphism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ function getSchemaForType<T>(type: Constructable<T>, baseSchema: Schema<T>): Sch
type SourceFromSchema<T> = T extends StrictSchema<unknown, infer U> | Schema<unknown, infer U> ? U : never;
type DestinationFromSchema<T> = T extends StrictSchema<infer U> | Schema<infer U> ? U : never;

type ResultItem<TSchema extends Schema> = { [P in keyof TSchema]: DestinationFromSchema<TSchema>[P] };
type ResultItem<TSchema extends Schema> = DestinationFromSchema<TSchema>;

export interface Mapper<TSchema extends Schema | StrictSchema, TResult = ResultItem<TSchema>> {
(data: SourceFromSchema<TSchema>[]): TResult[];
(data: SourceFromSchema<TSchema>): TResult;
Expand Down Expand Up @@ -137,7 +138,7 @@ export function morphism<

export function morphism<TSchema extends Schema, TDestination>(
schema: TSchema,
items: SourceFromSchema<TSchema> | null,
items: null,
type: Constructable<TDestination>
): Mapper<TSchema, TDestination>; // morphism({}, null, T) => mapper(S) => T

Expand Down

0 comments on commit 44b8ca2

Please sign in to comment.