This is obviously not strongly typed + the "fields" dont know what type they are. To solve this, we create a type to describe what a field contains and how to map it to a column (which is "typed"):
...
...
@@ -15,10 +15,10 @@ This is obviously not strongly typed + the "fields" dont know what type they are
typeFieldSchema<T>={T:T/* remember the type */,createColumn:CIFField=>Column<T>}
```
where column is just a function that for a given row returns a value of ``T``:
where column is just a simple interface returns a value of ``T`` for a given row:
In other words, the type ``TypedCategory`` has a property of type ``Column<_>`` for each property of the schema. ``Schema[F]['T']`` just says: extract type of property called ``T`` from property ``F`` in ``Schema``. ``Schema extends CategorySchema`` says that all properties of ``Schema`` must be of type ``FieldSchema<any>``.
In other words, the type ``TypedCategory`` has a property of type ``Column<_>`` for each property of the schema. ``Schema[F]['T']`` just says: extract the type of property called ``T`` from property ``F`` in ``Schema`` (see [mapped types in Typescript](https://www.typescriptlang.org/docs/handbook/advanced-types.html)). ``Schema extends CategorySchema`` says that all properties of ``Schema`` must be of type ``FieldSchema<any>``.
Finally, we just define a mapping, ``toTypedCategory``: