Property ‘then’ does not exist on type ‘void’.ts(2339)

A TypeScript error occurred – property ‘then’ does not exist on type ‘void’.ts(2339)

This error occurs when you are trying to use the ‘then’ method on a value of type ‘void’ in TypeScript.

In TypeScript, the ‘void’ type represents the absence of a value, meaning that it does not have any properties or methods. Therefore, when you try to call the ‘then’ method on a ‘void’ value, TypeScript raises an error indicating that the property ‘then’ does not exist on the ‘void’ type.

To resolve this error, you need to make sure that you are calling the ‘then’ method on a value of type ‘Promise’ instead of ‘void’. The ‘then’ method is used to handle the result of a Promise after it has been resolved.

Here is an example:

    
      // Create a Promise that resolves after 1 second
      const myPromise = new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve("Promise resolved");
        }, 1000);
      });
      
      // Call the then method on the Promise to handle the resolved value
      myPromise.then((result) => {
        console.log(result); // Output: "Promise resolved"
      });
    
  

Leave a comment