2

So I wanted to start rewriting my code from Screeps using Typescript. But for some reason instead of generating a Javascript code, it generates the same typescript code. Am I missing something from tsconfig.json file?

Left Typescript, right suppose to be Javascript

enter image description here

tsconfig.json File

{
  "compileOnSave": true,
  "compilerOptions": {
    "module": "es2015",
    "lib": [ "esnext" ],
    "target": "es2015",
    "moduleResolution": "Node",
    "outDir": "../",
    "baseUrl": "src/",
    "sourceMap": true,
    "strict": true,
    "experimentalDecorators": true,
    "noImplicitReturns": true,
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false,
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false
  },
  "exclude": [
    "node_modules"
  ]
}

Maybe I am missing from this file, I am new to typescript. Using Visual Studio 2017 Community.

4
  • 4
    The right pane looks like correct Javascript to me...? What part of it is invalid as Javascript? Commented Aug 3, 2018 at 23:11
  • Where you expecting ES5 output instead of ES6/ES2015? Commented Aug 3, 2018 at 23:19
  • Because I expected the class to be converted to a function, similar to this video: youtu.be/yn1IScE-TQQ?t=4m17s Commented Aug 3, 2018 at 23:21
  • 1
    Yes, that's correct after I changed to ES5 that generated the output that I expected, thank you for the help. Commented Aug 3, 2018 at 23:26

1 Answer 1

3

The output is JavaScript, compliant with ES6 (also known as ES2015). export, const, class, etc are all legal JavaScript.

If you want to generate code to run on old browsers, change target to es5 or es3

Sign up to request clarification or add additional context in comments.

1 Comment

Great, setting target to es5 solved the problem for me, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.