Created
August 9, 2019 18:08
-
-
Save davidwallacejackson/aa6bb2fe0cc468aa8b9af8f28f064f4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Serialized { | |
a: string, | |
b: string, | |
c: string | string[], | |
} | |
interface Deserialized { | |
field: number, //parsed from a | |
otherField: string, // parsed from b | |
yetAnotherField: string[] // parsed from c | |
} | |
interface Field<K extends keyof Deserialized, V = K[V]> { | |
parse: (serialized: Serialized) => V, | |
render: (value: V) => Partial<Serialized>, | |
} | |
const fields = { | |
field: { | |
parse: (serialized) => Number.parseFloat(serialized.a), | |
render: (value) => ({ a: value.toString() }), | |
}, | |
// ... etc for otherField and yetAnotherField | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment