Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next 13 - Using number constants for revalidate value make TS complain in VS Code #41951

Closed
1 task done
riffbyte opened this issue Oct 27, 2022 · 4 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@riffbyte
Copy link

riffbyte commented Oct 27, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
    Binaries:
      Node: 16.15.0
      npm: 8.12.1
      Yarn: 1.22.17
      pnpm: 7.1.3
    Relevant packages:
      next: 13.0.1-canary.0
      eslint-config-next: 13.0.0
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

For some weird reason whenever I use a constant for revalidate parameter of a page component, I get a TS error in VS Code stating that this is an invalid value. It looks like it's validating agains the constant name and not the value.

image

The app still runs and builds fine, and when running TSC manually, I don't get this error message.

Expected Behavior

revalidate should support both passing arbitrary values and variables as long as their type is correct.

Link to reproduction

https://stackblitz.com/edit/vercel-next-js-agx376

To Reproduce

Unfortunately I couldn't reproduce the issue on Stackblitz (maybe some VS Code settings are different), but the error message is definitely coming from the next typescript plugin, see this file

@riffbyte riffbyte added the bug Issue was opened via the bug report template. label Oct 27, 2022
@riffbyte riffbyte changed the title Next 13 - Can not use number constants for revalidate value Next 13 - Using number constants for revalidate value make TS complain in VS Code Oct 27, 2022
@shuding
Copy link
Member

shuding commented Oct 27, 2022

This is the correct behavior because these configurations should be statically analyzable (e.g. the compiler can know the information without executing the code). So things like export const revalidate = 1 + 1 or export const revalidate = anotherVariable will not work.

That said, the error message isn't great and it should explain this better. We will improve that part for sure, thanks for opening this issue 👍

@shuding shuding closed this as completed Oct 27, 2022
@riffbyte
Copy link
Author

Thanks for the clarification @shuding! I think it would make sense to also mention that in the docs to prevent confusion :)

@shuding
Copy link
Member

shuding commented Oct 28, 2022

I opened #42062 to improve it.

ijjk pushed a commit that referenced this issue Oct 30, 2022
…lly analyzable (#42062)

As per
#41951 (comment),
this PR improves the TS plugin error message when a non-literal
configuration is used:

<img width="902" alt="CleanShot 2022-10-28 at 07 36 31@2x"
src="https://user-images.githubusercontent.com/3676859/198650771-026a0430-d5bc-4826-9aef-b1bfb7947c6f.png">

Also a bug is fixed so string template literals (``const revalidate =
`auto`;``) will no longer result in an error.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

2 participants