▲ | kentonv 4 days ago | |||||||||||||||||||||||||
The placeholder value is an RpcPromise. Which means that all its properties are also RpcPromises. So `p.IsPerson` is an RpcPromise. I guess that's truthy, so the expression will always evaluate to `(p.FirstName + ' ' + p.LastName)`. But that's going to evaluate to '[object Object] [object Object]'. So your mapper function will end up not doing anything with the input at all, and you'll get back an array full of '[object Object] [object Object]'. Unfortunately, "every object is truthy" and "every object can be coerced to a string even if it doesn't have a meaningful stringifier" are just how JavaScript works and there's not much we can do about it. If not for these deficiencies in JS itself, then your code would be flagged by the TypeScript compiler as having multiple type errors. | ||||||||||||||||||||||||||
▲ | drysart 4 days ago | parent | next [-] | |||||||||||||||||||||||||
Yeah I'll definitely chalk this up to my not having more than a very very passing idea of the API surface of your library based on a quick read over just the blog post. On a little less trivial skim over it looks like the intention here isn't to map property-level subsets returned data (e.g., only getting the `FirstName` and `LastName` properties of a larger object); as much as it is to do joins and it's not data entities being provided to the mapping function but RpcPromises so individual property values aren't even available anyway. So I guess I might argue that map() isn't a good name for the function because it immediately made me think it's for doing a mapping transformation and not for basically just specifying a join (since you can't really transform the data) since that's what map() can do everywhere else in Javascript. But for all I know that's more clear when you're actually using the library, so take what I think with a heaping grain of salt. ;) | ||||||||||||||||||||||||||
▲ | Aeolun 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Couldn’t you make this safer by passing the map something that’s not a plain JS function? I confess to that being the only thing that had me questioning the logic. If I can express everything, then everything should work. If it’s not going to work, I don’t want to be able to express it. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | skybrian 4 days ago | parent | prev [-] | |||||||||||||||||||||||||
Another way to screw this up would be to have an index counter and do something different based on the index. I think the answer is "don't do that." | ||||||||||||||||||||||||||
|