Strategies for resolving the error: Incompatible Type 'unknown' cannot be assigned to type 'BlobPart'

One particular function call that I am dealing with is shown below

this.component.getXML({ format: true }, (error, currentXML) => {
  if (error) {
    console.error(error.message);
  }

  // do something with currentXML
});

However, I decide to leverage async await for a certain task. In order to achieve this, I made the following adjustments

async function someName() {
  const promise = new Promise((resolve, reject) => {
    this.component.getXML({ format: true }, (error, currentXML) => {
      if (error) {
        reject(error);
      }

      resolve(currentXML);
    });
  });

  try {
    const currentXML = await promise;

    const blob = new Blob([currentXML], { type: "text/xml" });
    const formData = new FormData();

    formData.append("file", blob, "filename.xml");
  } catch (error) {
    console.error(error.message);
  }
}

This approach works fine. The issue arises when attempting to create the blob using

const blob = new Blob([currentXML], { type: "text/xml" });
, resulting in an error message as follows:

Type 'unknown' is not assignable to type 'BlobPart'
Type '{}' is missing the following properties from type 'Blob': size, type, arrayBuffer, slice, and 2 more.

It seems that even though the output of

const currentXML = await promise;
is a string, explicitly defining it doesn't resolve the error.

Your insights would be greatly appreciated.

Answer №1

To address this issue, I successfully resolved it by incorporating the type Promise<string> in the following manner

const promise: Promise<string> = new Promise((resolve, reject) => {
  this.app.saveData({ formatting: true }, (error, updatedData) => {
    if (error) {
      reject(error);
    }

    resolve(updatedData);
  });
});

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

The jQuery data method retrieves an integer value instead of a string

HTML <div class="ui-droppable" data-number="P"></div> Javascript Source Inspection div.ui-droppable |... |--attributes:NamedNodeMap | |... | |--data-number | | |... | | |--nodeValue: "P" | | |... | | |--textContent: "P" | | |--va ...

What is the best approach to perform a search in mongoose based on specific query parameters?

I have a form that allows users to search for transactions by specifying the buyer name, item name, or both. This means I can receive any of these queries: localhost:8000/allPayments/?i=pasta localhost:8000/allPayments/?b=Youssef localhost:8000/ ...

How to link promises without relying on the 'then' method

I have an object named foo that has multiple methods implemented as promises using jQuery deferred. The current code structure looks like this: var foo = createNewFoo(); $.when(foo.method1(arg)) .then(foo.method2) .then(foo.method3); I want to re ...

Using Node.JS to read a huge file and inserting each line individually into a database

Dealing with a huge file containing over 100K JSON Strings, each on a separate line is proving challenging. My goal is to read each line, insert it into one database, and update another document in a different database with basic information from the initi ...

Selectize Fails to Populate Options Using Ajax

ExpressJS is the platform I am using to develop a management dashboard for a community project. Right now, my main concern is integrating a modal that allows users to add new games to a database. Although I am able to fetch data remotely, I am facing diffi ...

Tips for adjusting the height of a Safari extension during runtime

After successfully developing a Safari extension, I am facing an issue with adjusting the width and height of the popover dynamically at runtime. Can anyone provide insights on how to modify the dimensions of the popover based on its content? ...

Ways to configure several resolve statements in Angular's UI-router?

Is there a way to prevent the page from loading before the data is ready, avoiding the view updating while the page is still loading? I have been successful in using a 'resolve' in UI-router to run a method and fetch data before loading the page ...

Exploring the process of introducing a new property to an existing type using d.ts in Typescript

Within my src/router.ts file, I have the following code: export function resetRouter() { router.matcher = createRouter().matcher // Property 'matcher' does not exist on type 'VueRouter'. Did you mean 'match'? } In an ...

What is the best way to extract all image URLs from a website using JavaScript?

There are various methods to retrieve image src urls using JavaScript, such as utilizing document.images or by targeting all img elements and fetching their src attributes. However, I am currently unable to extract the image urls specified within CSS styl ...

What is the best way to display tip boxes for content that is added dynamically?

One of the challenges with my web page is that dynamically added content does not display tipboxes, unlike items present since the page load. I utilize the tipbox tool available at http://code.google.com/p/jquery-tipbox/downloads/list. To illustrate the i ...

The combination of touch events and jquery-ui sortable is not functioning properly on mobile devices as anticipated

Perspective: Developing a mobile web application involves using jquery-ui sortable to organize a list of items, with restrictions on sorting the first and last items. The Objective: The aim is to implement the jquery-mobile tap-hold event to allow users ...

Interface definition triggers an error when assigning a string literal to a field

When defining a string literal type in an interface, I encountered unexpected behaviors. interface IFoo { value: 'foo' | 'boo'; } Upon implementation of the interface in a class, I encountered an error: class Foo implements IFoo ...

Stretching the Mantine Accordion Section

The Mantine accordion requires that its content be of type Accordion.Item, as indicated in the documentation for the children props. This means that even functions returning AccordionItem will not be recognized. Therefore, only AccordionItem(s) created in ...

Managing errors that occur while handling JSON with AJAX by implementing a suitable backup plan

Imagine there is a user.json file stored on a web server that contains: { "name” : “ivana”, “age” : “27” } Now, I make a request to retrieve this JSON data using the following code: var user = $.ajax({ url: pathsample.com/user.js ...

French datepicker encountered an error when trying to set the date

Trying to showcase the datepicker in French, I have included the local's CDN. This is how my code looks: <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel=&q ...

Retrieve JSON object based on its unique identifier from a different JSON file

I am working with 2 API resources: and it returns JSON data like this: { "id": 771, "title": "Call to Alyce Herman - Engine Assembler", "assigned_with_person_id": 317, } provides ...

Unable to locate the file using ajax

Hello everyone, I'm new to working with ajax. I have a php file and an ajax file. My goal is simply to detect the php file from the ajax request that I am sending in ajax. <!DOCTYPE html> <html> <head> <script> function loadXM ...

Sending an array from the server to the client using Node and Express during page loading?

I am utilizing Node and Express in my project. The application fetches data from a remote database on page load and sends it to a handlebars template server-side. However, I would like this JSON data to also be accessible for client-side interactions. How ...

Leveraging jquery version 2.2.2 within a grails application

In an effort to ensure compatibility in a Grails project, we are looking to change the JavaScript library versions. We recently added AngularJS 1.5.2, which requires jQuery 2.1+ (source: https://docs.angularjs.org/misc/faq). Our current version of jQuery i ...

Create a unique CSS class that combines custom styling with the pre-defined classes provided by

Hello everyone, I'm curious if there is a way to create a custom CSS class that incorporates existing Bootstrap classes? For instance, take a look at the following snippet of HTML: <div class="text-primary center-block">Here is some text</ ...