I keep getting could be instantiated with a different subtype of constraint error when I return result that should fit the expected type of a function, and I can't understand what I'm doing wrong. Here's my code, all irrelevant details removed:
type User = { }
interface BasePageProps {
user: User
}
type GetServerSidePropsResult<P> =
| { props: P }
type PropsWithUser = <TProps extends BasePageProps>(
callback: (user: User) => Promise<Omit<TProps, 'user'>>
) => Promise<GetServerSidePropsResult<TProps>>
export const testFunc: PropsWithUser = async (callback) => {
const user = {}
return { props: {
user,
...(await callback(user))
} }
}
And here's the error I'm getting:
'{ user: {}; } & Omit<TProps, "user">' is assignable to the constraint of type 'TProps', but 'TProps' could be instantiated with a different subtype of constraint 'BasePageProps'.
Here's this example on TS Playground.
Why is the potential TProps that was instantiated with a different subtype a problem? How can I fix it?
P.S.: You may notice that these types are taken from Next.js. However, this problem has nothing to do with Next.js itself, so please don't it's tag to this question.