-
-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
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 would like to have the result value to be optional and allow
nullorundefined. - I would like to have the method removed from the type definition of the result value.
Probably onlysessionId,encryptedSessionIdand user-defined values are needed for the result value.
get(sessionId, callback) {
getSessionDataFromCustomDatabase(sessionId)
.then((data) => {
if (!data) {
// If the data simply does not exist, I want to do the following
callback(null, null) // ❌ TS2345: Argument of type 'null' is not assignable to parameter of type 'Session'.
// or
callback(null) // ❌ TS2554: Expected 2 arguments, but got 1.
// or
callback() // ❌ TS2554: Expected 2 arguments, but got 0.
return
}
callback(null, data) // ⚠ If you want to follow the type definition, you need to implement touch, save, regenerate, and other methods on the data.
})
.catch((error: Error) => {
// If the process fails, I want to do the following
callback(error) // ❌ TS2554: Expected 2 arguments, but got 1.
// or
callback(error, null) // ❌ TS2345: Argument of type 'null' is not assignable to parameter of type 'Session'.
})
}Currently, I have to do the following, but I feel it is because the original type definition is bad.
get(sessionId, callback) {
getSessinDataFromCustomDatabase(sessionId)
.then((data) => {
if (!data) {
callback(null, null as unknown as Fastify.Session) // Not at all type-safe.
return
}
callback(null, data as Fastify.Session) // Not at all type-safe.
})
.catch((error: Error) => {
callback(error, null as unknown as Fastify.Session) // Not at all type-safe.
})
}Motivation
No response
Example
No response
jsardev, kgoedecke and xcrzx
Metadata
Metadata
Assignees
Labels
No labels