Open tomdohnal opened 22 hours ago
The documentation example might be misleading. The cacheTag function uses rest parameters (...tags: string[]), so it expects individual string arguments rather than an array. Here's how to fix it:
// ❌ Incorrect - passing array
cacheTag(["tag-1", "tag-2"]);
// ✅ Correct - passing individual strings
cacheTag("tag-1", "tag-2");
The TypeScript signature is:
function cacheTag(...tags: string[]): void
See the type definition here
This means you can pass any number of string arguments, but they need to be passed as separate arguments, not as an array. The rest parameter syntax (...) will automatically collect them into an array internally. If you have an array of tags that you need to pass, you can spread them:
const tags = ["tag-1", "tag-2"];
cacheTag(...tags);
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/wizardly-breeze-j63t72?file=%2Fapp%2Fpage.tsx%3A6%2C3-6%2C32
To Reproduce
page.tsx
filecacheTag(["tag-1", "tag-2"]);
Current vs. Expected behavior
I expect to be able to pass an array of tags to the
cacheTag
function (as per the example given in the docs) but I see an error saying: "Argument of type 'string[]' is not assignable to parameter of type 'string'" insteadProvide environment information
Which area(s) are affected? (Select all that apply)
TypeScript
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
As other places in the docs pass multiple tags as separate arguments (rather than as an array) which is the actual type signature of the
cacheTag
function, I wonder if it's just the case of the docs being wrong here