I'd like to define an Adapter Schema, to convert one Object into another.
export type AdapterSchema<Source, Destination> = {
[key in keyof Partial<Source>]: {
target: keyof Destination;
convert: (source: Source[key]) => Destination[keyof Destination];
};
};
It should be possible to add a convert function, that converts the value of a property into the value of the target property.
interface Foo {
a : string;
}
interface Bar {
b : number;
c : string;
}
const schema : AdapterSchema<Foo,Bar> = { a : {target: 'b', convert: (value) => 'x'}}
I want the compiler to throw an error here, because 'x' is not of type number. My type is at least a bit type safe, because only types of Bar are allowed, but no error is thrown, because Bar has also a property of type string.
Can this be made more type safe?
Thanks in advance.