Not rely on the framework to write typescript, purely a new ts file, use the TSC compiled into js, ts file statement of variable, function name, an error:

Duplicate identifier  |  Duplicate function// This is a named function and class errorCopy the code

or

Cannot redeclare block-scoped variable // This is an errorCopy the code

In fact, we write ts code is no problem, but TS will be declared variables, named functions, class are put in the global scope, after the generation of JS file, js file variables, functions, class will be repeated with ts file.

The solution

At the top of the TS file add:

export {}
Copy the code

Compiling the ts file again, you can see the compiled js file added:

"use strict";
exports.__esModule = true;
Copy the code

It treats the entire file as a module. So you don’t get an error.