Have you ever encountered the following validation error while coding in Velo?
Cannot redeclare block-scoped variable x.
Take a look at the below video which shows it in a more visualized way (for a const named 'schema'):
Why does this happen?
Velo currently uses a TypeScript compiler for autocomplete and code validations. Yes, Velo users TypeScript typing system to validate your Velo JS code :-)
Read the explanation in this post, it will clarify things.
If typescript recognizes a code file as a script (code that doesn’t include import or export statements) it shares global scope with all other script files. In Velo, there’s currently one global scope for everything (including frontend and backend - same scope). So Basically this could happen in two scenarios.
One is that you are trying to declare a variable which you declared already in another “script" file
Another scenario is that you declare a variable that collides with one of the properties of the global scope object. “name” is such an example when writing frontend code in Velo because it’s already been declared by the WebWorker (our frontend runtime environment)
What can you do about it?
Change your variable name (clever, hu?)