Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

typescript intellisense not working for payload type?

default discord avatar
Thinh Nguyenlast year
10

I started with the

next-payload

repo and once I got to creating access control functions, I noticed that I kept getting

any

types despite providing one in the generic.



Am I missing something from my

tsconfig,json

file? Also using generated types which are 🙌

  • discord user avatar
    alessiogr
    last year

    what type does it show for the req object?

  • default discord avatar
    Thinh Nguyenlast year

    req is showing up as

    any

    ,

  • Can you go to definition of the Access type? What does it show?

  • default discord avatar
    Thinh Nguyenlast year

    It appears to be correct according to the docs. TS server is running fine

    Screenshot_2023-07-22_at_3.52.26_PM.png
  • And if you go to your user type def?

  • default discord avatar
    Thinh Nguyenlast year

    this is my generated type from running

    payload generate:types


    I was able to reproduce the same issue with a fresh installation of nextjs and next-payload

    Screenshot_2023-07-22_at_4.46.51_PM.png
  • But only in next-payload?

  • default discord avatar
    Thinh Nguyenlast year

    Yes, type completion is working as expected on a regular payload server, but unfortunately not on next-payload

  • discord user avatar
    alessiogr
    last year

    I've been having the exact same error where req is any on my project - but for PayloadHandler (used in collection endpoints).



    I managed to fix it by installing express and @types/express. No idea why that fixed it or why that caused it though

  • default discord avatar
    Thinh Nguyenlast year

    Thank you @alessiogr, this definitely fixed it! Actually just having

    @types/express

    is sufficient enough to provide the type completion.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.