I came across a similar question that I thought would be helpful: How to maintain ES6 syntax when transpiling with Typescript, but unfortunately, it didn't solve my issue... It's slightly different.
When running yarn tsc --project tsconfig.json
on the file:
// ./index.tsx
class Person {
public name: string;
constructor(name: string) {
this.name = name;
}
_run = () => {
console.log('I\'m running!')
}
}
let person = new Person('John Doe');
console.log(person.name);
The transpiled code looked like this:
// ./index.js
class Person {
constructor(name) {
this._run = () => {
console.log('I\'m running!');
};
this.name = name;
}
}
let person = new Person('John Doe');
console.log(person.name);
Now, how can I achieve the same code as the input without any additional postprocessing steps?
This is my tsconfig.json configuration:
{
"compilerOptions": {
"baseUrl": ".",
"alwaysStrict": true,
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"allowJs": true,
"checkJs": false,
"module": "ESNext",
"target": "ESNext",
"jsx": "react",
"moduleResolution": "node",
"types": ["node"],
"lib": ["dom", "es6", "es2017", "es2018", "es2019", "es2020","esnext"]
},
"linebreak-style": [true, "LF"],
"typeAcquisition": {
"enable": true
},
"include": [
"**/*"
],
"exclude": [
"node_modules",
"**/*.test.ts",
"**/*.test.tsx",
"dist"
]
}