This course has been updated! We now recommend you take the TypeScript Fundamentals, v3 course.

Check out a free preview of the full TypeScript 3 Fundamentals, v2 course:
The "Making Anys Explicit" Lesson is part of the full, TypeScript 3 Fundamentals, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Mike describes the second step in converting JavaScript to TypeScript.

Get Unlimited Access Now

Transcript from the "Making Anys Explicit" Lesson

[00:00:00]
>> Mike North: Step 2, you will start with your tests passing, you will ban implicit anys. And this is a tsconfig compiler option, noImplicitAny, true. So setting that to true means, instead of TypeScript falling back to any in places where it can't figure things out through inference, it will throw an error at you.

[00:00:26] Not throw an error but it will give you a compile error.
>> Mike North: So you're gonna then have basically a to-do list, and it's mostly going to consist of implicit anys that now have turned into compile errors. And you are gonna go through and provide meaningful types where you can, and where you can't, you'll use an explicit any.

[00:00:49] You'll add a type annotation saying, this is an any, I am explicitly saying, whatever is fine here. This is a good time for me to highlight DefinitelyTyped, which is an open source project that provides ambient type information, right? This is like the DTS files. It provides separate npm packages that you can bring in and it'll, ideally, perfectly lay on top of the underlying JavaScript code base that you're used to using.

[00:01:21] For example, if you want to use Lodash, which unless something has changed recently, that is not written in TypeScript. It's written in regular JavaScript. You can import the Lodash types, and you'll get all of the benefits that you get from typed code. But it's really like the implementation and then the type information laying on top of it.

[00:01:43] DefinitelyTyped publishes out to thousands of libraries and they all are in the npm package scope at typed or at types. So you'll see at types slash lodash. And if you look in the package JSON on this workshop project, I think you'll see at types slash node. So that has the fs module and the path module, all the type information there, right?

[00:02:11] So this is a good time to sort of start bringing that in as a way of combating these implicit anys. And then you're going to get your test passing again, and this is a second independent poll request.