Typescript
  • Introducão
  • Primeiros Passos
    • Por que TypeScript
  • JavaScript
    • Igualdade
    • Referências
    • Null vs. Undefined
    • this
    • Closure
    • Number
    • Truthy
  • Futuro JavaScript Agora
    • Classes
      • Classes Emit
    • Arrow Functions
    • Rest Parameters
    • let
    • const
    • Destructuring
    • Spread Operator
    • for...of
    • Iterators
    • Template Strings
    • Promise
    • Generators
    • Async Await
  • Project
    • Compilation Context
      • tsconfig.json
      • Which Files?
    • Declaration Spaces
    • Modules
      • File Module Details
      • globals.d.ts
    • Namespaces
    • Dynamic Import Expressions
  • Node.js QuickStart
  • Browser QuickStart
  • TypeScript's Type System
    • JS Migration Guide
    • @types
    • Ambient Declarations
      • Declaration Files
      • Variables
    • Interfaces
    • Enums
    • lib.d.ts
    • Functions
    • Callable
    • Type Assertion
    • Freshness
    • Type Guard
    • Literal Types
    • Readonly
    • Generics
    • Type Inference
    • Type Compatibility
    • Never Type
    • Discriminated Unions
    • Index Signatures
    • Moving Types
    • Exception Handling
    • Mixins
  • JSX
    • React
    • Non React JSX
  • Options
    • noImplicitAny
    • strictNullChecks
  • Errors in TypeScript
    • Interpreting Errors
    • Common Errors
  • NPM
  • Testing
    • Jest
    • Cypress
  • Tools
    • Prettier
    • Husky
    • Changelog
  • TIPs
    • String Based Enums
    • Nominal Typing
    • Stateful Functions
    • Bind is Bad
    • Currying
    • Type Instantiation
    • Lazy Object Literal Initialization
    • Classes are Useful
    • Avoid Export Default
    • Limit Property Setters
    • outFile caution
    • JQuery tips
    • static constructors
    • singleton pattern
    • Function parameters
    • Build Toggles
    • Barrel
    • Create Arrays
    • Typesafe Event Emitter
  • StyleGuide
  • TypeScript Compiler Internals
    • Program
    • AST
      • TIP: Visit Children
      • TIP: SyntaxKind enum
      • Trivia
    • Scanner
    • Parser
      • Parser Functions
    • Binder
      • Binder Functions
      • Binder Declarations
      • Binder Container
      • Binder SymbolTable
      • Binder Error Reporting
    • Checker
      • Checker Diagnostics
      • Checker Error Reporting
    • Emitter
      • Emitter Functions
      • Emitter SourceMaps
    • Contributing
Powered by GitBook
On this page
  • TS2304
  • TS2307
  • TS1148
  • Catch clause variable cannot have a type annotation
  • Interface ElementClass cannot simultaneously extend types Component and Component

Was this helpful?

  1. Errors in TypeScript

Common Errors

PreviousInterpreting ErrorsNextNPM

Last updated 5 years ago

Was this helpful?

In this section we explain a number of common error codes that users experience in the real world.

TS2304

Samples:

Cannot find name ga Cannot find name $ Cannot find module jquery

You are probably using a third party library (e.g. google analytics) and don't have it declared. TypeScript tries to save you from spelling mistakes and using variables without declaring them so you need to be explicit on anything that is available at runtime because of you including some external library ().

TS2307

Samples:

Cannot find module 'underscore'

You are probably using a third party library (e.g. underscore) as a module () and don't have the ambient declaration file for it ().

TS1148

Sample:

Cannot compile modules unless the '--module' flag is provided

Checkout the .

Catch clause variable cannot have a type annotation

Sample:

try { something(); }
catch (e: Error) { // Catch clause variable cannot have a type annotation
}

TypeScript is protecting you from JavaScript code in the wild being wrong. Use a type guard instead:

try { something(); }
catch (e) {
  if (e instanceof Error){
    // Here you go.
  }
}

Interface ElementClass cannot simultaneously extend types Component and Component

This happens when you have two react.d.ts (@types/react/index.d.ts) in the compilation context.

Fix:

  • Delete node_modules and any package-lock (or yarn lock) and npm install again.

  • If it doesn't work, find the invalid module (all modules used by your project should have react.d.ts as a peerDependency and not a hard dependency) and report it on their project.

more on how to fix it
more on modules
more on ambient declarations
section on modules