Skip to content

typescript types don't work properly #211

@Zamiell

Description

@Zamiell

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.25.1

Plugin version

7.1.0

Node.js version

20.9.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

10

Description

The types don't work properly.
e.g.:

declare module "@fastify/secure-session" {
  interface SessionData {
    userID: number;
  }
}

async function login(
  request: FastifyRequest,
  reply: FastifyReply,
): Promise<FastifyReply> {
  request.session.set("usersID", 123);
}

In the above code snippet, we made a typo, and typed it as "usersID" instead of "userID". Oops! But we don't get a compiler error - it just works, and the bug makes its way to production.

Is there some way for a declaration merge to get rid of the string index signature? Because that's the root cause of the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions