How to generate TypeScript code without transpiling async operations

Is there a way to utilize the TypeScript compiler solely for the purpose of stripping type annotations without transpiling async functions? Is there an option akin to { target: 'esInfinite' }? The rationale behind this question is that some browsers already have support for async functions, so I am seeking a build target where these functions remain unaffected.

For instance:

async function bar(x : string) : Promise<void> {}

expected result:

async function bar(x) {}

Answer №1

To maintain the functionality of async/await, adjust the target in your tsconfig.json file to ES2017.

{
  "compilerOptions": {
    .....
    "target": "ES2017",
    .....
  }
}

Ensure that your application's run-time natively supports this change!!!

PS: Starting from April 2018, AWS Lambda now offers Nodejs 8 support. You should be able to utilize the provided configuration for it.

Answer №2

A request for this functionality has been previously made in the following link. Support for es2016 and es2017 is expected to be included in the upcoming Community milestone and in TypeScript 2.1.

Answer №3

One day, I decided to make a clever workaround by replacing the metro-react-native-babel-preset npm package with a public git repository. In the package.json file, I swapped out the following line under devDependencies:

    "metro-react-native-babel-preset": "^0.73.9",

and instead used...

    "metro-react-native-babel-preset": "github:svpease/metro-react-native-babel-preset-minus-async#v1.0.1",

This modification removed the async-to-generator plugin, allowing async functions to be detected like so:

(() => {}).constructor.name === 'Function'; // true
Object.getPrototypeOf(async () => {}).constructor.name === 'AsyncFunction'; // true

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to interact with the existing xpath element

I am having trouble locating a specific element in Protractor while using Protractor + Jasmine + POM. Interestingly, I can find the element with count 1 in the developer console. Despite adding a try and catch block for element location, it always ends up ...

Error: JSON parsing error caused by an unexpected character '<' at the start of the JSON data while executing an Angular post request to a

Using Angular 2, I have been attempting to send data from my Angular application through a POST request to a PHP file on the server. However, I keep encountering an error that reads "SyntaxError: Unexpected token < in JSON at position 0". Below is the c ...

Steps to fix the issue of 'Property 'foo' lacks an initializer and is not definitely assigned in the constructor' while utilizing the @Input decorator

What is the proper way to initialize a property with an @Input decorator without compromising strict typing? The code snippet below is triggering a warning: @Input() bar: FormGroup = new FormGroup(); ...

Creating a standard arrow function in React using TypeScript: A Step-by-Step Guide

I am currently working on developing a versatile wrapper component for Apollo GraphQL results. The main objective of this wrapper is to wait for the successful completion of the query and then render a component that has been passed as a prop. The componen ...

Tips for efficiently calling a function without the need to check if it exists beforehand

I'm looking for a way to access the formik props outside of the form without constantly checking if a function exists before calling it when using refs. Any suggestions on how to achieve this? function BasicInfo({ event, initialValues, onSubmi ...

Creating a javascript variable in c#

Currently, I am working on incorporating the selected index text from a DropDownList into a JavaScript string. My approach involves storing the text in a hidden field and retrieving it through C# to ensure the JavaScript variable retains its value even aft ...

Could it be that the AmCharts Drillup feature is not fully integrated with AngularJS?

UPDATE: Check out this Plunker I created to better showcase the issue. There seems to be an issue with the Back link label in the chart not functioning as expected. I'm currently facing a challenge with the AmCharts Drillup function, which should a ...

Is there a way to design a catalog page for my website that doesn't include a shopping cart or detailed product pages?

I am looking to create a catalogue feature similar to Newegg's for my website, but with a simplified approach. I have never attempted something this advanced before and I am wondering if it is possible to achieve. My plan is to use PHP and JS for the ...

The loop feature in Swiper.js seems to be malfunctioning and not functioning as

I'm currently in the process of setting up a carousel using swiper.js and here is my setup: { slidesPerView: 1, slidesPerColumn: 1, initialSlide: this.initialSlide, loop: true } As expected, I'm encountering an issue where dupl ...

MongoDB date query with $gte and $le operators mm/dd/yy

Apologies in advance for any language errors. The problem I am dealing with involves a column in the database called "Date" inside the "startOn" Object. This setup creates a structure like "startOn.Date" with data format as yyyy/dd/mm. For example, if we ...

Double Tap Required to Update AngularJS Scope

Controller: // Modal Controller app.controller("ModalCtrl", ["$scope", "$filter", function($scope, $filter) { var date = new Date(); var currentDate = $filter('date')(new Date(), 'MM/dd/yyyy'); // Form Submit Actions $scope.s ...

Creating an HTML design with divs: a trio of pictures that adjusts in size to match the viewport (sl

As a newcomer to HTML and CSS, I find myself nearing completion of my website, with the final obstacle being an image slider in the background. The Challenge: The images are not perfectly centered within the viewport. Specifically, the first image needs ...

Updating nested arrays using mongoose

I'm currently facing an issue while trying to update the value of an object using $ set in order to pass an Object into a nested array element. The problem is that the first element is updated instead of the one I am querying. I'm unsure about wh ...

Implementing multiple actions in an onClick function to update state using React Redux

I'm currently facing an issue with updating the Redux state. The problem arises when I try to execute an onclick function that triggers multiple actions, but the mapStateToProps doesn't get updated in time due to the asynchronous nature of action ...

Display the element containing the targeted content using jQuery

Is there a way to style all li elements with a specific content without assigning them a unique id or class? <ul class="list"> <li>test</li> <li>test2</li> <li>test</li> </ul> I want to make all ...

Handling file uploads in ReactJS and managing files from the faux path C:/fakepath/file

When attempting to upload a file using a simple form that will be processed by my back-end python code, I encountered an issue where the uploaded file path shows as C:\fakepath\test.txt. After some research, I discovered that this behavior is du ...

Establish a buffering system for the <video> element

Currently, I am facing an issue with playing videos from a remote server as they take an extended amount of time to start. It appears that the entire video must be downloaded before playback begins. Is there a way to configure the videos so they can begi ...

What are some ways I can utilize Babel in standalone mode to convert an HTML import into a variable declaration?

I am trying to utilize the Babel plugin babel-plugin-transform-html-import-to-string to dynamically transform my code in the browser client. However, the babel-plugin-transform-html-import-to-string is designed to run on node with file libraries, which are ...

Utilizing React's multiple states for enhancing click event functionality

Here's the scenario: I am currently developing a Simon-Says game app using React Native. In this game, the user is shown a sequence of flashing buttons and must press them in the correct order. My main concern is figuring out how to utilize two diffe ...

Organizing NodeJS modules in a way that mirrors Maven's groupId concept

I am making the switch to NodeJS after working extensively with Maven. In Maven, we are familiar with the groupId and artifactID, as well as the package name when starting a new project. However, in NodeJS, I only see a module name. The concept of groupI ...