Skip to content

Add support for typed session data #115

@moeriki

Description

@moeriki

Prerequisites

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

🚀 Feature Proposal

I'd like to type the data I put in and get out of the session.

Motivation

I don't like type-casting any on every session.get().

Example

// fastify-secure-session/index.d.ts
export interface Session {
  // …
  get<Key extends keyof SessionData>(key: Key): SessionData[Key] | undefined;
  set<Key extends keyof SessionData>(key: Key, value: SessionData[Key] | undefined): void;
}

export interface SessionData {
  [key: string]: any;
}
# user code
declare module 'fastify-secure-session' {
  interface SessionData {
    codeVerifier: string;
    tokenSet: TokenSet;
  }
}

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