Replies: 1 comment
-
Could you do: import type { cookies } from 'next/headers'
type Args = Parameters<typeof cookies>
type Result = Awaited<Result<typeof cookies>> Stuff like that should work. It tells TS that during compile time, after type verification, it can drop that import from the process. I think, I've used the triple slash directive on a package that needed the extended fetch from Next.js: https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html Look at your project /// <reference types="next" /> But, I think my suggestion above should do the trick |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Goals
To be able to import next types like ReadonlyRequestCookies or the type of a monkey-patched Fetch, without the need to import the whole next.
Non-Goals
No response
Background
I am writing a typescript function, in an npm package, that accepts as input the result of next cookies() function and performs some extraction/manipulations.
The function would be something similar to:
const extractCustomCookies = (cookies: ReadonlyRequestCookies) => cookies.get('customCookie');
I tried installing next as a devDependency, but I saw that the type cannot be imported.
Also a few random types seems to break in other parts of my npm package, like some useContext now seems to use a canary version of react.
Proposal
I propose to discuss a way to provide next types only to whoever need them to create wrapper functions
Beta Was this translation helpful? Give feedback.
All reactions