Skip to content

TypeScript - Extend hook type #1570

Answered by flacial
flacial asked this question in Q&A
Discussion options

You must be logged in to vote

This worked but we'll have to specify the type every time:

interface Session extends DefaultSession {
  lessonStatus: {
    starGiven: string
    passedAt: Date | null
    lessonId: number
  }[]
  user: {
    id: number
    username: string
    name: string
    isAdmin: boolean
    isConnectedToDiscord: boolean
  }
  submissions: Submission[]
}

export declare type SessionContext<R extends boolean = false> = R extends true
  ?
      | {
          data: Session
          status: 'authenticated'
        }
      | {
          data: null
          status: 'loading'
        }
  :
      | {
          data: Session
          status: 'authenticated'
        }
      | {
          data: null

Replies: 1 comment

Comment options

flacial
Mar 10, 2022
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by flacial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant