twitter-types
twitter-types copied to clipboard
Users can have a "status" field
Certain Twitter APIs, for example https://dev.twitter.com/rest/reference/get/users/lookup, come with the user's "last status", if you have permission to read it. It would be nice if this "status" were available.
It might make sense to separate the types of User so that /users/lookup
returns a UserWithStatus, since some APIs will never have this field available. I can try to implement this if you like.
In trying to implement this, I discovered that the kind of status that comes with the user is different from a regular kind of status because it doesn't have a "user" field. So there's two kinds of statuses -- those that have a user field, and those that don't (presumably because they're already inside a user).
How can this be implemented, then? I had three ideas:
- Introduce a LastStatus type which is like the Status type but without the
user
field. This leads to lots of code duplication but it seems pretty straightforward conceptually. A Status has a User, which might have a LastStatus. I was working on a PR to add this (see https://github.com/glasserc/twitter-types/tree/add-status), but in so doing, I broke the tests, which now go into an infinite loop and I have no idea why. - Add a parameter to the Status type which is the type of the User field. So a regular status could be a
Status User
, and the user'sstatus
field would be of typeStatus ()
or something to indicate that the user wasn't available. This seems somewhat disruptive to existing users of the library but maybe it could be made to work. - We could just have the
User
field onStatus
beMaybe User
. This seems very disruptive and quite conceptually ugly so I haven't tried to make this work.
Are there other, more elegant ways to have this kind of convoluted semi-recursive dependency?