Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

TypeScript: ES5 target support #418

Closed
vguzev opened this issue May 4, 2017 · 27 comments
Closed

TypeScript: ES5 target support #418

vguzev opened this issue May 4, 2017 · 27 comments
Assignees

Comments

@vguzev
Copy link

vguzev commented May 4, 2017

Is it possible to add TypeScript configuration with ES5 target?
We can't use getters/setters with current version of TypeScript 1.8.10...

For example when I try to run this kata
https://www.codewars.com/kata/590b85b745eaa415e10000b1/train/typescript
I'm getting errors:
../home/codewarrior/solution.ts(28,7): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.

In command line this can be done via command:
tsc task.ts -t ES5

@kazk
Copy link
Member

kazk commented May 5, 2017

This should be possible.
I think the target is supposed to be es6 already, but it's not working.
There's unused /runner/tsconfig.json with

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs"
  }
}

@jhoffner
TypeScript support needs some fix and updates (#380).
As far as I know, using @types modules will allow us to remove all the TypeScript stuff at the root of the project. And @types will be included in compilation by default so /// comments can go away.
See the blog The Future of Declaration Files.

@jhoffner
Copy link
Member

jhoffner commented May 5, 2017

Sounds good. Would love to get this up-to-date. We will need to make sure to make /// backwards compatible if it isn't aren't already with 2.0.

@kazk
Copy link
Member

kazk commented May 5, 2017

...I didn't think about the compatibility issues with TypeScript 1.8 and 2.0+ :(
Maybe it's not as easy as I thought then. I don't know TypeScript much so I won't be able to do this anytime soon unless someone can let me know the requirements.

@jhoffner
Copy link
Member

jhoffner commented May 5, 2017

Maybe it's not as easy as I thought then

If we can support both 1.8 and 2.0 at the same time then we should be fine. I guess we could just manually copy the 1.8 files into the node_modules folder on the image (unless there is a better way to support two versions via npm).

@kazk
Copy link
Member

kazk commented May 5, 2017

docker/node.docker#L23-L24 installs the latest stable release and Codewars currently has v2.2.1.

# Install TypeScript
RUN npm -g install typescript
// Kumite
const cp = require('child_process');
console.log(cp.execSync('which tsc', {encoding:'utf8'}));
//=> /.npm-global/bin/tsc
console.log(cp.execSync('tsc -v', {encoding:'utf8'}));
//=> Version 2.2.1

@jhoffner
Copy link
Member

jhoffner commented May 5, 2017

Hmm, should have locked that to a version...

@vguzev
Copy link
Author

vguzev commented May 5, 2017

The problem is not in version of typescript. You should use latest version of typescript on your servers.
But keep in mind that "tsc" is transpiler, i.e. it transforms programs, written in TypeScript to programs written in JavaScript. By default it transpiles to ES3. But as you know not all features are available in ES3. For example getters/setters are available only in ES5. I.e. you need some kind of configurations for TypeScript, so that you could tell tsc to generate JS code according to ES5 standard and then use javascript compiler that understands ES5 (for example Node v.6.6.0/Babel).

I want to say that there must be TypeScript analogue for this dialogue:
image
with options ES3, ES5, and etc...

@kazk
Copy link
Member

kazk commented May 5, 2017

@vguzev
That should be fixed by tsc --module commonjs --target ES6 in lib/runners/typescript.js#L46, if I'm not misunderstanding.

I was trying to cleanup the codebase while doing so.

@kazk
Copy link
Member

kazk commented May 5, 2017

Multiple targets can be done through opts.languageVersion and setting the default to ES3 shouldn't break existing ones.

@vguzev
Copy link
Author

vguzev commented May 5, 2017

Have not idea what does that mean )
Here is the simple TypeScript snippet which can be compiled with ES5/ES6 targeting only, but not with ES3:

class A {
 get b() {
  return true;
 }
}

@kazk
Copy link
Member

kazk commented May 5, 2017

@vguzev
Sorry, maybe I should have opened a new issue.

I understand what this issue is about, and making -t/--target configurable shouldn't be hard to do. So I started to discuss how to proceed with this and also fix some existing issues. Using @types should resolve #380 and that's why the version became a concern. This issue is not affected.

@kazk
Copy link
Member

kazk commented May 5, 2017

I just re-read #380 and the issue is about Array.from not recognized which might be the same target issue and not outdated typings. Array.from was specified in ES2015/ES6.

@vguzev
Copy link
Author

vguzev commented May 5, 2017

Perhaps switching the default target from ES3 to ES6 could be the workaround for now...?

@kazk
Copy link
Member

kazk commented May 5, 2017

We can make -t/--target configurable to one of "ES3", "ES5", "ES6"/"ES2015", "ES2016" (through opts.languageVersion) and set "ES3" as default for backward compatibility. This should allow users to select the target similar to JavaScript's language versions when necessary.

@vguzev
Copy link
Author

vguzev commented May 5, 2017

Cool! That would be great! )

@kazk
Copy link
Member

kazk commented May 6, 2017

@jhoffner what do you think of making targets configurable as described above?
If you think this is valid approach, can you change the title to something like "TypeScript: Make target configurable" so it's easier to see the goal? Also maybe create TypeScript Epic and put this and #380 in it. For #380 and using @types, I think we should do it separately.

I won't be able to do it right now since my TODO list is getting long, but this one should be relatively easy.

@jhoffner
Copy link
Member

jhoffner commented May 6, 2017

If we were to use targets as language versions, we would probably want to do 1.8/ES5, 2.2/ES5, 2.2/ES6, etc.

I'm wondering if the accidental update from 1.8 to 2.2 caused any backwards compatibility issues with existing content. If it didn't, we could just leave it upgraded and not worry about 1.8 at all.

As far as ES5 vs ES6, I'm thinking it's probably safe to switch to using ES6 as the target without ES3/5 support at all. ES5 is in the past, lets leave it there.

@kazk
Copy link
Member

kazk commented May 6, 2017

Yeah, TypeScript's compatibility needs to be looked into.

For targets, I think the issue will be allowing sloppy mode or not. JavaScript (ECMAScript) is very careful with backward compatibility because of "don't break the web". I'm assuming the default target "ES3" is sloppy and "ES5+" is strict. So just keeping "ES3" and the latest standard might be enough.

I found a tsc option --noImplicitUseStrict. We might be able to just target the latest standard by using this?

@vguzev
Copy link
Author

vguzev commented May 11, 2017

Hi! Any updates?
I started working on Typescript katas https://www.codewars.com/collections/learning-typescript and I need modern version of tsc compiler for some katas... (

@kazk
Copy link
Member

kazk commented May 11, 2017

@vguzev we won't be able to have this feature on Codewars anytime soon. There're some things we need to look into and decide. Also, @jhoffner will be on vacation starting tomorrow.

If you can provide information about any breaking changes between TypeScript 1.8 and 2.2, that'll help.
tsc is v2.2 by accident and we need to ensure v1.8 compatibility.

image


@jhoffner maybe #316 (Invalid 'reference' directive syntax.) is caused by the update?

@vguzev
Copy link
Author

vguzev commented May 12, 2017

Oups... I meant not the "modern compiler", but configurable targets. The problem is that tsc v.2.2.1 also have ES3 target enabled by default. There is a PR out there microsoft/TypeScript#15466 for switching default target to ES5, but it is not available in current version of tsc.

@vguzev
Copy link
Author

vguzev commented Jul 25, 2017

Meanwhile typescript 2.4.2 was published several days ago... any updates on this issue?

@kazk
Copy link
Member

kazk commented Jul 26, 2017

I guess we can forget about 1.8?
If so, we can have language versions 2.4/ES3 (default) and 2.4/ES6.
I'll open a PR.

@vguzev
Copy link
Author

vguzev commented Jul 26, 2017

@kazk Great! Don't forget to set --target es6 as parameters, because by default es3 target will be set even with the new versions of compiler. See microsoft/TypeScript#10117

@kazk
Copy link
Member

kazk commented Jul 26, 2017

@vguzev see #476.
This implementation accepts any of the targets supported by tsc 2.4, but Codewars will probably only show few major ones like 2.4/ES3 and 2.4/ES6.
Let me know if I missed anything.

@vguzev
Copy link
Author

vguzev commented Jul 26, 2017

@kazk Looks OK for me :)

@kazk kazk self-assigned this Aug 3, 2017
@vguzev
Copy link
Author

vguzev commented Aug 7, 2017

When will it be available on codewars.com? Currently I see only version 1.8.10 of typescript:
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants