next-translate icon indicating copy to clipboard operation
next-translate copied to clipboard

"'const' declarations must be initialized" when using the satisfies operator

Open markcnunes opened this issue 2 years ago • 6 comments

What version of this package are you using? next-translate: 2.0.6 next-translate-plugin: 2.0.5

What happened? I get the following error when using the satisfies operator in a project with the next-translate and Next.js app directory.

Here is a reproduction of the issue https://codesandbox.io/p/sandbox/next-js-app-direcotyr-with-satisfies-operator-forked-hj8zqw?file=%2Fapp%2Fpage.tsx%3A6%2C1-6%2C6

I tested the same project without the next-translate and the satisfies operator works fine. https://codesandbox.io/p/sandbox/next-js-app-direcotyr-with-satisfies-operator-bjcd8k

What did you expect to happen? I expected the satisfies operator not to be an issue. This wasn't an issue on the pages directory.

Are you willing to submit a pull request to fix this bug? Yes, if someone directs me to how it can be fixed.

markcnunes avatar Jun 05 '23 12:06 markcnunes

Why do you thing this issue is related with next-translate? 🤔 thanks!

aralroca avatar Jun 15 '23 13:06 aralroca

Ok, I think it is related. The parser we use is TypeScript but a version prior to 4.9 which is the one with the satisfier. It could be this, but it's strange, I'll need to investigate it more.

aralroca avatar Jun 15 '23 13:06 aralroca

I reviewed the issue over the weekend and it seems that the problem lies in the Typescript or Babel configurations. The code "satisfies Record<string, { name: string }>" appears to be compiled as "satisfies, Record; () => { name: string; }."

I noticed that you recently updated Typescript to higher than 4.9 in next-translate, as well as other packages to support the satisfies operator. However, the issue still persists. I'm wondering if this problem could be caused by the next-translate-plugin, as I noticed it is still using Typescript version 4.5.2.

https://github.com/aralroca/next-translate-plugin/blob/main/package.json#L56

I attempted to update it to at least version 4.9, but encountered some issues with the utils file in Typescript 4.8 due to deprecated functions. I haven't worked with Node manipulation by Typescript yet, so I couldn't successfully fix that file. However, I hope this information saves you some debugging time.

markcnunes avatar Jun 19 '23 09:06 markcnunes

Probably the problem is in the version of TypeScript inside the next-translate-plugin. In order to updated we need to update also the TypeScript parser because has some breaking changes

aralroca avatar Jun 19 '23 09:06 aralroca