Skip to content

Commit

Permalink
fix: loosen type checking for NextApiHandlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed Jan 9, 2024
1 parent 2aa405f commit fdfec8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ export interface NtarhInitPagesRouter<NextResponseJsonType = unknown>
* The actual Pages Router route handler under test. It should be an async
* function that accepts `NextApiRequest` and `NextApiResult` objects (in
* that order) as its two parameters.
*
* Note that type checking for `res.send` and similar methods was retired in
* NTARH@4. Only the `response.json` method returned by NTARH's fetch wrapper
* will have a typed result.
*/
pagesHandler: NextApiHandler<NextResponseJsonType>;
pagesHandler: NextApiHandler<any>;
appHandler?: undefined;
/**
* `params` is passed directly to the handler and represents processed dynamic
Expand Down
5 changes: 4 additions & 1 deletion test/unit-index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,10 @@ describe('::testApiHandler', () => {

await testApiHandler<{ a: number }>({
pagesHandler: async (_, res) => {
// @ts-expect-error: b does not exist (this test "fails" if no TS error)
// ? Formerly we would expect an error to be thrown here, but in
// ? NTARH@4 we've relaxed the type checking so that only fetch::json
// ? is affected. I believe this leads to more accurate and more
// ? useful type checking for NTARH users.
res.send({ b: 1 });
},
test: async ({ fetch }) => {
Expand Down

0 comments on commit fdfec8c

Please sign in to comment.