test.ts
import {
useSession,
createError,
type H3Event,
type EventHandlerRequest,
type SessionConfig
} from 'h3'
interface SessionData {
userId?: string;
}
function getSessionConfig() : SessionConfig {
return {
password: '',
name: '',
cookie: {
sameSite: 'strict',
httpOnly: true,
secure: true
}
}
}
async function useAppSession(event: H3Event<EventHandlerRequest>) {
const config = getSessionConfig()
return useSession<SessionData>(event, config)
}
async function validateSessionUser(event: H3Event<EventHandlerRequest>) {
const session = await useAppSession(event)
const { userId } = session.data
if (userId === undefined) {
throw createError({
status: 401
})
}
return userId
}
export { useAppSession, validateSessionUser }
Code above triggers an error with oxlint-tsgolint v0.20.0 (v0.19.0 works correctly):
× typescript-eslint(no-unnecessary-type-arguments): This is the default value for this type parameter, so it can be omitted.
╭─[server/utils/test.ts:30:21]
29 │
30 │ return useSession<SessionData>(event, config)
· ───────────
31 │ }
╰────
SessionData can't be omitted, because it provides typed data. W/o it, the data is any.
test.ts
Code above triggers an error with
oxlint-tsgolintv0.20.0(v0.19.0works correctly):SessionDatacan't be omitted, because it provides typeddata. W/o it, thedataisany.