-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Describe the bug
When using morphism inside the function with generic types - it could not assign SourceType to SourceFromSchema<StrictSchema<D, SourceType>>
To Reproduce
Steps to reproduce the behavior:
Just run this file with ts-node locally. Also I commented specific error inside tranformWithGenerics function
import {createSchema, morphism, StrictSchema} from 'morphism';
interface Target {
target: string;
}
interface Source {
source: string;
}
const source: Source = {
source: '123',
};
const map = {
target: 'source',
};
const schema = createSchema<Target, Source>(map);
const transformed = morphism(schema, source);
console.log('transformed:', transformed);
function transform(document: Source, m: StrictSchema<Target, Source>): Target {
return morphism(m, document);
}
const transformedWithFunction = transform(source, map);
console.log('transformedWithFunction:', transformedWithFunction);
function transformWithGenerics<T, S>(document: S, m: StrictSchema<T, S>): T {
return morphism(m, document);
// above line shows error:
// Overload 2 of 6, '(schema: StrictSchema<T, S>, data: SourceFromSchema<StrictSchema<T, S>>): DestinationFromSchema<StrictSchema<T, S>>', gave the following error.
// Argument of type 'S' is not assignable to parameter of type 'SourceFromSchema<StrictSchema<T, S>>'.
}
const transformedWithGenerics = transformWithGenerics<Target, Source>(source, map);
console.log('transformedWithGenerics:', transformedWithGenerics);Expected behavior
I would expect it to properly work with generics, or am I missing something here?
Desktop (please complete the following information):
- OS: MacOs Catalina 10.15.6
- ts-node:
9.0.0 - typescript:
3.8.3
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels