File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,11 +30,33 @@ export interface DiscriminatorPropertyOptions {
3030 property : string ;
3131
3232 /**
33- * An arrow function returning an object matching a discriminator to its subtype.
33+ * An arrow function returning an object with as key the discriminator and value the type to
34+ * instantiate.
3435 */
3536 types : ( ) => { [ k : string ] : Serializable < any > } ;
3637}
3738
39+ /**
40+ * Handle subtype lookup by matching the value of the given property to the types map. e.g.
41+ * ```
42+ * discriminatorProperty({
43+ * property: 'type',
44+ * types: () => ({
45+ * foo: Foo,
46+ * bar: Bar,
47+ * }),
48+ * })
49+ * ```
50+ * with the following data:
51+ * ```
52+ * {
53+ * "type": "foo"
54+ * }
55+ * ```
56+ * This will result in TypedJSON looking up the value of `data.type`, here `foo`, in the map
57+ * provided by `types`, resulting in an object of type `Foo`. When serializing `Foo`, the `type`
58+ * property will be added with value `foo`.
59+ */
3860export function discriminatorProperty (
3961 { property, types} : DiscriminatorPropertyOptions ,
4062) : ObjectInheritanceOptions {
You can’t perform that action at this time.
0 commit comments