This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add type safety to NextApiRequest | |
| type TypedNextApiRequest<Q, B> = Omit<NextApiRequest, 'body' | 'query'> & { | |
| // make req.query have the keys we expect, but AsQuery will turn the values | |
| // into strings or string arrays. Partial is there because you never know | |
| // whether the request will be well-formed | |
| query: Partial<AsQuery<Q>>; | |
| // make req.body have the keys and value types we expect, however, know that | |
| // the data will be deserialized from JSON, so, for example, Dates will be | |
| // strings. again Partial is there to enforce defensive code | |
| body: Partial<Deserialized<B>>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Filtering | |
| export function isFulfilled<T>( | |
| value: PromiseSettledResult<T>, | |
| _index?: number, | |
| _array?: PromiseSettledResult<T>[], | |
| ): value is PromiseFulfilledResult<T> { | |
| return value.status === 'fulfilled'; | |
| } |
OlderNewer