Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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
  };


It looks like "row" is already the object you want. Why make a copy of it? And why copy it by copying each property individually?


Row is just a dumb object, without a type.


No, "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.)


So is the obj you created.


Ah, I meant to specifically decorate it as a Typescript object, but forgot to add it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: