user1432882
user1432882

Reputation: 1152

Error TS2451: Cannot redeclare block-scoped variable '$'

Getting the following error when trying to compile with typescript 2.1:

TypeScript error: node_modules/@types/jquery/index.d.ts(3770,13): Error TS2451: Cannot redeclare block-scoped variable '$'.

Not sure what this means or how to fix.

Upvotes: 8

Views: 10603

Answers (1)

A-Diddy
A-Diddy

Reputation: 642

You're likely importing and/or declaring JQuery multiple times and TypeScript is letting you know. Obviously, having duplicate declarations can lead to problems, especially if you're using plugins that attach themselves to the current $ instance. If $ is redeclared later, the plugins may no longer be available.

The correct thing to do would be to move all declarations into a single location, such as your index or main. However, if that's not possible, just tell TypeScript to ignore the duplicate declarations and carry on by adding the following property to your tsconfig.json:

{
  "compilerOptions": {
    ...
    "skipLibCheck": true,
    ...
  }
}

Upvotes: 6

Related Questions