4 ms·
Not sure what you mean by running ES6 code under Typescript. It is my understanding that Typescript 'transpiles' to whatever flavor of Javascript you need, and
by stareatgoats 8y ago
Not sure what you mean by running ES6 code under Typescript. It is my understanding that Typescript 'transpiles' to whatever flavor of Javascript you need, and then the code is executed as Javascript.
If your question is whether you can just change the file extension of a working ES6 file to .ts without Typescript complaining then answer is 'yes', you should be able to do that no problem.
Edit: of course there is little sense in doing nothing more than that, but it is a good starting point for decorating existing Javascript with TS features.
- Someone1234 8y agoThe biggest pain-point with renaming a ES6 file to *.TS is that TypeScript will flag every library or browser specific object you reference as missing. That isn't wrong behavior on TS's part, just getting started with TypeScript is very configuration heavy, particularly for targeting browsers.
- jahewson 8y agoYou can use the ‘allowJs’ flag to have the compiler accept unmodied JavaScript and for untyped modules you can use shorthand ambient module declarations so they use the ‘any’ type, with one line of code.
- superpermutat0r 8y agoIf your target is ES5 you will have to provide polyfills. Typescript will unfortunately typecheck even if you don't have polyfills and you'll get runtime errors with your ES5 target. They specifically said they won't provide polyfills and they Will continue to typecheck even if your target does not support the standard function.