TypeScript and the Error: Cannot Redeclare Block Scoped Variable <Name>

Hi, Devs!

Who are getting start in Typescript could face this error: “Cannot Redeclare Block Scoped Variable Name” and it means a concept into that language.

Let’s see an example:

The error is coming because we have a TypeScript feature….


This content originally appeared on DEV Community and was authored by Luiz Calaça

Hi, Devs!

Who are getting start in Typescript could face this error: "Cannot Redeclare Block Scoped Variable Name" and it means a concept into that language.

Let's see an example:

Cannot Redeclare Block Scoped Variable Name

The error is coming because we have a TypeScript feature.

1 - The file needs to be declared as a module (exports) with its own scope.
2 - The script into file will be comprehended in a global scope.

The first example is the 2 option. So, how can we solve that? Let's see another example with the export:

export and create a scope module

Therefore, when we use the export it's created a module with its own scope and not shared in global scope.

Contacts
Email: luizcalaca@gmail.com
Instagram: https://www.instagram.com/luizcalaca
Linkedin: https://www.linkedin.com/in/luizcalaca/
Twitter: https://twitter.com/luizcalaca


This content originally appeared on DEV Community and was authored by Luiz Calaça


Print Share Comment Cite Upload Translate Updates
APA

Luiz Calaça | Sciencx (2022-02-18T01:09:54+00:00) TypeScript and the Error: Cannot Redeclare Block Scoped Variable <Name>. Retrieved from https://www.scien.cx/2022/02/18/typescript-and-the-error-cannot-redeclare-block-scoped-variable-name/

MLA
" » TypeScript and the Error: Cannot Redeclare Block Scoped Variable <Name>." Luiz Calaça | Sciencx - Friday February 18, 2022, https://www.scien.cx/2022/02/18/typescript-and-the-error-cannot-redeclare-block-scoped-variable-name/
HARVARD
Luiz Calaça | Sciencx Friday February 18, 2022 » TypeScript and the Error: Cannot Redeclare Block Scoped Variable <Name>., viewed ,<https://www.scien.cx/2022/02/18/typescript-and-the-error-cannot-redeclare-block-scoped-variable-name/>
VANCOUVER
Luiz Calaça | Sciencx - » TypeScript and the Error: Cannot Redeclare Block Scoped Variable <Name>. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/18/typescript-and-the-error-cannot-redeclare-block-scoped-variable-name/
CHICAGO
" » TypeScript and the Error: Cannot Redeclare Block Scoped Variable <Name>." Luiz Calaça | Sciencx - Accessed . https://www.scien.cx/2022/02/18/typescript-and-the-error-cannot-redeclare-block-scoped-variable-name/
IEEE
" » TypeScript and the Error: Cannot Redeclare Block Scoped Variable <Name>." Luiz Calaça | Sciencx [Online]. Available: https://www.scien.cx/2022/02/18/typescript-and-the-error-cannot-redeclare-block-scoped-variable-name/. [Accessed: ]
rf:citation
» TypeScript and the Error: Cannot Redeclare Block Scoped Variable <Name> | Luiz Calaça | Sciencx | https://www.scien.cx/2022/02/18/typescript-and-the-error-cannot-redeclare-block-scoped-variable-name/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.