Я уже нашел этот вопрос и считаю, что он должен помочь: Как сохранить синтаксис ES6 при переносе с Typescript , но без везения ... Это немного по-другому.
В моем случае, когда yarn tsc --project tsconfig.json
файл с:
// ./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);
стал похож на:
// ./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);
В конце концов, как я могу получить тот же код, что и на вход? Например, без постобработки.
My tsconfig. json:
{
"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"
]
}