Importing modules from "next/dist/compiled/..."
Answered
Welsh Springer Spaniel posted this in #help-forum
Welsh Springer SpanielOP
Hey guys. I'm trying to type some helper functions that wrap the
Is it ok to import from
Thanks!
cookies function from "next/headers" and I'm trying to type my parameters. Copilot suggested I import these types...import { RequestCookie } from "next/dist/compiled/@edge-runtime/cookies";Is it ok to import from
next/dist/compiled or should I be retrieving this type through a different path or through some other means?Thanks!
Answered by Giant panda
Don't rely on these internals and leverage TypeScript instead using
Parameters<typeof cookies> or ReturnType<typeof cookies> or similar approaches.4 Replies
Giant panda
Don't rely on these internals and leverage TypeScript instead using
Parameters<typeof cookies> or ReturnType<typeof cookies> or similar approaches.Answer
Welsh Springer SpanielOP
Ooo nice, that's exactly the sort of thing I was looking for! Thank you so much! @Giant panda
Welsh Springer SpanielOP
Ah so, not so easy, it seems. The ReturnType for
Being "readonly", it's specifically omitting the types I'm hoping to use...
cookies looks like this: type ReadonlyRequestCookies = Omit<RequestCookies, 'set' | 'clear' | 'delete'> & Pick<ResponseCookies, 'set' | 'delete'>;Being "readonly", it's specifically omitting the types I'm hoping to use...
Welsh Springer SpanielOP
Oh i'm an idiot, ignore me...