Refactor Services and Quick Fixes with Typescript 2.5

Akash Gutha
InstructorAkash Gutha
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

This lesson covers the Refactoring services and Quick fixes provided by Typescript 2.5

[00:00] I made a simple function that takes in the radius and height and calculates the volume of the container by taking in the radius and the height. Now, if I set up this block of code and refactor it using extract function into function volume, we can see that it generates a new function inside the scope of the volume function.

[00:19] We will rename this function so that it reflects our context better. We can also this new refactoring services on conditional blocks. Let's elect this conditional block, and use the refactoring service extract function into module scope. This will extract the logic into our outermost block. Let's rename this.

[00:38] As you can see, it has correctly identified the parameters required and passed in into the function. You can also see that it is returning the correct logic with the correct type. TypeScript 2.5 also gives us services to quickly fix some common mistakes.

[00:55] Here, the developer has used JS doctype assertion to bind the type of X to any. We can quickly fix by using the quick fix provided by the TypeScript service. The same can also be done for the number.

[01:11] Here, we are trying to bind Z to the type of code.bad, but code is the interface, and bad is a property of the interface. We are trying to bind Z to the type of number, but this isn't the correct syntax. We can also quickly fix by using the quick fix, which will convert it into the exact TypeScript syntax.

egghead
egghead
~ 9 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today