Migrating each file

When the build system is set up, you can start with migrating files. It is easiest to start with files that do not depend on other files, as these do not depend on types of other files. To migrate a file, you must rename the file extension to .ts, convert the module format to ES modules, correct types that are inferred incorrectly, and add types to untyped entities. In the next sections, we will take a look at these tasks.

Converting to ES modules

In TypeScript files you cannot use CommonJS or AMD directly. Instead you must use ES modules, like we did in the previous chapters. For an import, you must choose from these:

  • import * as name from "package", imports the whole package, similar to var name = require("package") in CommonJS. ...

Get TypeScript: Modern JavaScript Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.