> [!info]
> when I tried to build my custom js script in obsidian, it generate many other different stuff which custom js fail to recognise. It is because the latest typescript has a lot of features which vanilla js doesn’t support. Therefore we need to set the build target to an older version.
The TypeScript code you've provided is being transpiled into JavaScript in a way that includes a lot of boilerplate code to handle the asynchronous functionality (`async/await`). This is typical when targeting older JavaScript versions (like ES5) that do not natively support `async/await`. To minimize this transformation, consider the following steps:
1. **Target a Newer ECMAScript Version**: If you can target a newer version of ECMAScript (like ES2017 or later), the transpiled JavaScript code will be much cleaner because these versions natively support `async/await`. To do this, you need to change the `target` option in your `tsconfig.json` file. For instance:
```json
{
"compilerOptions": {
"target": "ES2017",
// ... other options
}
}
```
2. **Use a Simpler Transpilation Tool**: If you are using a tool like Babel or a complex TypeScript configuration, it might be worth simplifying your toolchain. Sometimes, the default TypeScript compiler with minimal configuration can produce cleaner output.
3. **Manually Simplify Code**: If you have control over the TypeScript code and its use of modern features, you can write your TypeScript in a way that results in simpler JavaScript. For example, avoiding `async/await` in favor of Promises can sometimes reduce the complexity of the transpiled code.
Here's an example of how your TypeScript code might look after transpilation when targeting ES2017:
```ts
class RunLinterEditor {
async invoke() {
console.log("run linter editor");
}
}
```
Transpiled to ES2017 JavaScript:
```js
class RunLinterEditor {
async invoke() {
console.log("run linter editor");
}
}
```
As you can see, targeting a newer ECMAScript version can significantly reduce the complexity of the transpiled code. The key is that newer JavaScript versions understand `async/await` natively, so there's no need for the TypeScript compiler to add all the extra boilerplate code to emulate this functionality.