Categories
TypeScript Answers

How to fix the ‘cannot redeclare block scoped variable’ error with TypeScript?

Spread the love

Sometimes, we want to fix the ‘cannot redeclare block scoped variable’ error with TypeScript.

In this article, we’ll look at how to fix the ‘cannot redeclare block scoped variable’ error with TypeScript.

How to fix the ‘cannot redeclare block scoped variable’ error with TypeScript?

To fix the ‘cannot redeclare block scoped variable’ error with TypeScript, we should make sure we didn’t declare the same variable more than once.

For instance, if we write

import * as co from "./co";
const co = 1;

then we’ll get the ‘cannot redeclare block scoped variable’ error since we import a module and set its value to co and we also declared the co variable and set it to 1.

So we declared the same variable twice.

Likewise, we shouldn’t write

let co = 1;
const co = 1;

to declare a variable twice.

Conclusion

To fix the ‘cannot redeclare block scoped variable’ error with TypeScript, we should make sure we didn’t declare the same variable more than once.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *