-
Notifications
You must be signed in to change notification settings - Fork 0
Move to TypeScript
The first common approach to move the code from Javascript to TypeScript would simply rename the file extension from .js to .ts.
Doing this will mark the file with lots of red underline marks, which are going to show possible sources of error on your code. Hovering those, it's possible to see what TypeScript detects as a possible error source and this gives us a hint on how we could fix those.
Some of the possible errors sources displayed on your text editor / ide can be easyly fixed just by changing the way in which some of the variables are declared on the code - while others really will depend on other TypeScript fundamentals.
In the code provided, those errors which can be easly fidex, are marked with Cannot assing to 'xxxx' because it's a constant. Changing those declarations from const to let would be a possible fix.
At first glance, seeing all those errors showing up on your screen can be really intimidating - specially when we think about all the additional code required to fix those errors - , but once you get hold of this, things will become clear, confortable and your coding worl will have lots of improvements. This happens not because TypeScript is creating new bugs on the code, but only showing where those bugs already existed.
Those notes were written while watching the tutorial videos while taking the classes from the online course Learn TypeScript on Scrimba.
Because english is not my mother language, they can contain some typos and everything written here is based on my understanding about the discussed topics and may not be 100% accurate.
If you want the full course, support the instructor by buying their course on Scrimba.
- Home
- Introduction
- Introduction to TypeScript
- The Pizza Application
- Move to TypeScript
- Defensive Coding
- Typing variables
- Typing Pizza App: part 1
- Custom types
- Typing Pizza App: part 2
- Nested Object types
- Optional Properties
- Typing Pizza App: part 3
- Array Types
- Typing Pizza App: part 4
- Literal Types
- Unions
- Typing Pizza App: part 5
- Typing Pizza App: part 6
- Typing Pizza App: part 7
- Returning Types
- Typing Pizza App: part 8
- Any Type
- Typing Pizza App: part 9
- Utility Types
- Typing Pizza App: part 10
- Generics
- Typing Pizza App: part 11