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
Copy file name to clipboardExpand all lines: book-content/chapters/09-typescript-only-features.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Based on what I've told you so far, you might be thinking of TypeScript as just
4
4
5
5
But TypeScript actually has a few runtime features that don't exist in JavaScript. These features are compiled into JavaScript, but they are not part of the JavaScript language itself.
6
6
7
-
In this chapter we'll look at several of these TypesScript-only features, including parameter properties, enums and namespaces. Along the way, we'll discuss benefits and trade-offs, as well as when you might want to stick with JavaScript.
7
+
In this chapter we'll look at several of these TypeScript-only features, including parameter properties, enums and namespaces. Along the way, we'll discuss benefits and trade-offs, as well as when you might want to stick with JavaScript.
8
8
9
9
## Class Parameter Properties
10
10
@@ -18,7 +18,7 @@ class Rating {
18
18
}
19
19
```
20
20
21
-
That the constructor includes `public` before the `value`prameter and `private` before the `max` parameter. In JavaScript, this compiles down to code which assigns the parameters to properties on the class:
21
+
That the constructor includes `public` before the `value`parameter and `private` before the `max` parameter. In JavaScript, this compiles down to code which assigns the parameters to properties on the class:
22
22
23
23
```typescript
24
24
classRating {
@@ -471,7 +471,7 @@ This information will become crucial later when we look at the namespace's key u
471
471
472
472
Imagine ES modules, with `import` and `export`, never existed. In this world, everything you declare is in the global scope. You'd have to be careful about naming things, and you'd have to come up with a way to organize your code.
473
473
474
-
This is the world that TypeScript was born into. Module systems like CommonJS (`requre`) and ES Modules (`import`, `export`) weren't popular yet. So, namespaces were a crucial way to avoid naming conflicts and organize your code.
474
+
This is the world that TypeScript was born into. Module systems like CommonJS (`require`) and ES Modules (`import`, `export`) weren't popular yet. So, namespaces were a crucial way to avoid naming conflicts and organize your code.
475
475
476
476
But now that ES modules are widely supported, you should use them over namespaces. Namespaces have very little relevance in modern TypeScript code, with some exceptions which we'll explore in our chapter on global scopes.
477
477
@@ -493,4 +493,4 @@ But the question remains: should you use them? TypeScript will likely never stop
493
493
494
494
But I prefer writing code in the spirit of the language I'm using. Writing "JavaScript with types" keeps the relationship between TypeScript and JavaScript crystal-clear.
495
495
496
-
However, this is my personal preference. If you're working on a large codebase that already uses these features, it is _not_ worth the effort to remove them. Reaching a decision as a team, and staying consistent, is the key.
496
+
However, this is my personal preference. If you're working on a large codebase that already uses these features, it is _not_ worth the effort to remove them. Reaching a decision as a team and staying consistent are the keys.
0 commit comments