I’ve encountered a problem with module augmentation and merging. Here’s my next-auth.d.ts
file for augmentation:
Now, whenever I import “NextAuthOptions,” ESLint flags an issue. Although I can disable this check, I would prefer to understand how to properly perform module augmentation and merging.
Both of the following code snippets have issues:
1st
import NextAuth from "next-auth";
declare module 'next-auth' {
export interface Session {
user?: User
expires: string
}
export interface User {
id: number;
username: string
}
export {NextAuthOptions} from "next-auth";
}
The 1st snippet complains that NextAuthOptions
is incorrectly typed, whenever I try to import it.
2nd
// import NextAuth from "next-auth";
declare module 'next-auth' {
export interface Session {
user?: User
expires: string
}
export interface User {
id: number;
username: string
}
export {NextAuthOptions} from "next-auth";
}
The 2nd snippet complains that it doesn’t know anything about the default exports ANextAuth
, whenever I try to import it.
And I am aware of the limitations regarding default exports in TypeScript module augmentation: Link on ts merging-docs
But Is there a correct way to properly infer types using module augmentation and merging?
I would exptect that the types will be infered properly and linting will not complain using the 1st option.