4 ms·
I totally agree - but this has the advantage of returning something like a well-defined object that hews to an interface, as long as you have the model set up.
by pavel_lishin 2y ago
I totally agree - but this has the advantage of returning something like a well-defined object that hews to an interface, as long as you have the model set up.
The trade-offs are usually worth it, vs, doing something like:
const row = db.query('select whatever from wherever');
const obj = {
id: row.id,
brand: row.brand,
... etc
};
- mg 2y agoIt looks like "row" is already the object you want. Why make a copy of it? And why copy it by copying each property individually?
- pavel_lishin 2y agoRow is just a dumb object, without a type.
- mg 2y agoSo is the obj you created.
- pavel_lishin 2y agoAh, I meant to specifically decorate it as a Typescript object, but forgot to add it.
- dragonwriter 2y agoNo, "row" is a generic type, all concrete rows have concrete types narrowing the generic type with an ordered sequence of element tags and element types. (Relations are typed similarly to rows, since they are containers for rows of homogenous type.)