Skip to content

Fix assert types#215

Merged
mcollina merged 1 commit into
fastify:mainfrom
tmcw:issue-214-fix-types
Mar 9, 2026
Merged

Fix assert types#215
mcollina merged 1 commit into
fastify:mainfrom
tmcw:issue-214-fix-types

Conversation

@tmcw

@tmcw tmcw commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

This clarifies that assert can be used with 2-3 arguments, but not with a single argument. The second argument must be the status code as a number.

Checklist

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the TypeScript typings for fastify.assert() (and its helper methods) to reflect the actual runtime contract: the status code must be provided as the second argument, with an optional message as the third.

Changes:

  • Make code a required parameter (typed as number) across assert, assert.ok, and related assertion helpers in types/index.d.ts.
  • Update types/index.test-d.ts to use the new required-code calling patterns.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
types/index.d.ts Tightens the Assert function/method signatures to require a status code.
types/index.test-d.ts Updates the type-level tests to call assert APIs with the required status code parameter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread types/index.test-d.ts
This clarifies that assert can be used with 2-3 arguments, but
not with a single argument. The second argument must be the status
code as a number.
@tmcw
tmcw force-pushed the issue-214-fix-types branch from f5dcef2 to 69e948b Compare March 7, 2026 18:05

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
mcollina merged commit 70787cc into fastify:main Mar 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Types for fastify.assert() are incorrect

3 participants