I have a project with javascript codebase. I would like start gradually shifting to typescript and also ensure that the existing javascript code stays on ES5 level. I.e. safeguard that ES6 features would be transpiled to ES5.
I thought that this could be solved by introducing just tsc to the build chain. The tsconfig.json has target for ES5 and tsc is set to process both typescript ja javascript files.
But appararently tsc does not transpile javascript files to ES5 level. Or am I missing something in my setup?
My guess is that I still need to add babel for the build chain to ensure that all code going to be executed in browser is at ES5 level.
Simple example below:
tstest.js containg ES6 feature:
var arr = ["a", "b", "c"];
console.log(arr.includes("b"));
Transpiling is not happening for javascript:
/tmp> tsc -t ES5 -allowJs -outDir ./transpiled tstest.js
/tmp> cat transpiled/tstest.js
var arr = ["a", "b", "c"];
console.log(arr.includes("b"));
includes
. – Paleo