You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this section we explain a number of common error codes that users experience in the real world.
3
+
4
+
## TS2304
5
+
Samples:
6
+
> `Cannot find name ga`
7
+
> `Cannot find name $`
8
+
> `Cannot find module jquery`
9
+
10
+
You are probably using a third party library (e.g. google analytics) and don't have it `declare`d. 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 ([more on how to fix it][ambient]).
11
+
12
+
## TS2307
13
+
Samples:
14
+
> `Cannot find module 'underscore'`
15
+
16
+
You are probably using a third party library (e.g. underscore) as a *module* ([more on modules][modules]) and don't have the ambient declaration file for it ([more on ambient declarations][ambient]).
17
+
18
+
## TS1148
19
+
Sample:
20
+
> Cannot compile modules unless the '--module' flag is provided
21
+
22
+
Checkout the [section on modules][modules].
23
+
24
+
## Catch clause variable cannot have a type annotation
25
+
Sample:
26
+
```js
27
+
try { something(); }
28
+
catch (e:Error) { // Catch clause variable cannot have a type annotation
29
+
}
30
+
```
31
+
TypeScript is protecting you from JavaScript code in the wild being wrong. Use a type guard instead:
32
+
```js
33
+
try { something(); }
34
+
catch (e) {
35
+
if (e instanceofError){
36
+
// Here you go.
37
+
}
38
+
}
39
+
```
40
+
41
+
## Interface `ElementClass` cannot simultaneously extend types `Component` and `Component`
42
+
This happens when you have two `react.d.ts` (`@types/react/index.d.ts`) in the compilation context.
43
+
44
+
**Fix**:
45
+
* Delete `node_modules` and any `package-lock` (or yarn lock) and `npm install` again.
46
+
* 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.
In this section we explain a number of common error codes that users experience in the real world.
3
-
4
-
## TS2304
5
-
Samples:
6
-
> `Cannot find name ga`
7
-
8
-
You are probably using a third party library (e.g. google analytics) and don't have it `declare`d. 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 ([more on how to fix it][ambient]).
9
-
10
-
## TS2307
11
-
Samples:
12
-
> `Cannot find module 'underscore'`
13
-
14
-
You are probably using a third party library (e.g. underscore) as a *module* ([more on modules][modules]) and don't have the ambient declaration file for it ([more on ambient declarations][ambient]).
15
-
16
-
## TS1148
17
-
Sample:
18
-
> Cannot compile modules unless the '--module' flag is provided
19
-
20
-
Checkout the [section on modules][modules].
21
-
22
-
## Catch clause variable cannot have a type annotation
23
-
Sample:
24
-
```js
25
-
try { something(); }
26
-
catch (e:Error) { // Catch clause variable cannot have a type annotation
27
-
}
28
-
```
29
-
TypeScript is protecting you from JavaScript code in the wild being wrong. Use a type guard instead:
30
-
```js
31
-
try { something(); }
32
-
catch (e) {
33
-
if (e instanceofError){
34
-
// Here you go.
35
-
}
36
-
}
37
-
```
38
-
39
-
## Interface `ElementClass` cannot simultaneously extend types `Component` and `Component`
40
-
This happens when you have two `react.d.ts` (`@types/react/index.d.ts`) in the compilation context.
41
-
42
-
**Fix**:
43
-
* Delete `node_modules` and any `package-lock` (or yarn lock) and `npm install` again.
44
-
* 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.
45
-
46
-
47
-
## For search indexing
48
-
You can ignore reading this. This section is for search engine indexing.
49
-
50
-
> Other modules that people tend to use and get errors:
51
-
* Cannot find name $
52
-
* Cannot find module jquery
53
-
54
-
[ambient]: ../types/ambient/d.ts.md
55
-
[modules]: ../project/modules.md
1
+
# Errors
2
+
In this section we discuss how to read and understand TypeScript errors. We follow this with common errors and their solutions.
0 commit comments