Closed chadacious closed 1 year ago
So I can make it work using intersection with something like this:
const mainInfo = (await moviedb.movieInfo(
{
id: tmdbId,
append_to_response:
"alternative_titles,videos,credits,release_dates,images",
},
{
timeout: LONG_AXIOS_TIMEOUT,
}
)) as MovieResponse & { release_dates: MovieReleaseDatesResponse };
But it seems a little complicated. Maybe that is how you intended it to be though.
Yeah, props for a "beginner" figuring this out!
The catch with the append_to_response
is that it's quite dynamic, although I think it is be possible to include the types... I've actually never personally used append_to_response
. Once I see the response I'll have a better idea of how to accommodate it. I think it's possible and worth investigating.
You know, the more I think about the solution using intersection on the specific props, the more I feel like that is actually a very reasonable way to handle appendToResponse. Perhaps it would just be helpful to include it in the documentation with a minimal example like:
await moviedb.movieInfo({ id: tmdbId, append_to_response: "release_dates" }))
as MovieResponse & { release_dates: MovieReleaseDatesResponse };
There's my 2cents anyway.
Thanks for sharing this @chadacious I also think this should be in the documentation.
I have added some documentation about this. Thanks again for finding a solution @chadacious
I'm just getting into typescript, and attempting to implement the latest moviedb-promise in my project. Where I'm stuck is in how to specify the type when including appendToResponse in my movieInfo call.
I thought maybe I could use typescript intersection but it doesn't seem to work:
So then I figured I could at least cast the mainInfo from above into what I wanted, but that isn't quite working either, I just get undefined:
const releaseDatesUS = (mainInfo as MovieReleaseDatesResponse).results
returns undefined.How do I properly access the appendToResponse props that are not included in MovieResponse?