1

I started to study Angular, but i can't get trough the problem with convert typescript file to javascript. I've created AngularCLI project and simple typescript file:

    class Example {
  msg = 'Some message';
}

and i tried to convert it to js with tsc command: tsc example.tsc. This is javascript file which was generated:

var Example = /** @class */ (function () {
    function Example() {
        this.msg = 'Some message';
    }
    return Example;
}());

And i've got some errors

node_modules/@types/selenium-webdriver/remote.d.ts:139:29 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

I think (or even sure) the problem is in javascript version (even error says that). This is tsconfig.json file:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

So i did what was suggested. I changed module, target, lib to atleast es2015 ( everything together and each separately) - it didnt help. I tried a lot of solutions from SO, jetbrain forum etc but nothing worked for me.

I use webstorm 2018.3 version. Node version is 10.14.1. Tsc version is 3.1.6.

Aisekai
  • 25
  • 10
  • What steps are you using to compile? Are you compiling, for instance, from Web Storm or from the command line? – Shaun Luttin Dec 01 '18 at 20:27
  • AngularCLI project with Webstorm. Typescript file to javascript - with command line in webstorm using: "tsc filename.tsc" comand. – Aisekai Dec 01 '18 at 20:46
  • 1
    Possible duplicate of [Angular: Can't find Promise, Map, Set and Iterator](https://stackoverflow.com/questions/35660498/angular-cant-find-promise-map-set-and-iterator) – Shaun Luttin Dec 01 '18 at 21:18
  • I linked you to another question that might have the answer for you. It looks like there are a handful of ways to solve the problem, and choosing which method to use depends on your specific environment. – Shaun Luttin Dec 01 '18 at 21:19

1 Answers1

3

Your updated tsconfig.json looks good now that it targets es2018. The problem now is how you are compiling. When I asked how you compile you wrote:

... with command line in webstorm using: "tsc filename.tsc" comand.

When we pass files to the compiler, the compiler ignores our tsconfig.json. The official tsconfig.json documentation says this:

When input files are specified on the command line, tsconfig.json files are ignored.

If you want to pass specific files on the command line and to compile with specific options, pass those options (e.g. the lib option) on the command line.

tsc filename.ts --lib es2018
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
  • Thanks, that's worked. Is there a way to generate .js file from .ts inside webstorm before add this file to website? – Aisekai Dec 01 '18 at 22:20
  • I'm afraid I am not familiar with WebStorm. I only know how to build TypeScript from the command line. – Shaun Luttin Dec 02 '18 at 00:03