Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to solve 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type. for typescript

I got error for const image = new Image(); like this

'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.

and

Expected 1 arguments, but got 0.

How to solve error like that?

const onPreview = async (file: UploadFile) => {
    let src = file.url as string;
    if (!src) {
      src = await new Promise((resolve) => {
        const reader = new FileReader();
        reader.readAsDataURL(file.originFileObj as RcFile);
        reader.onload = () => resolve(reader.result as string);
      });
    }
    const image = new Image();
    image.src = src;
    const imgWindow = window.open(src);
    imgWindow?.document.write(image.outerHTML);
  };
like image 949
Shitta 25 Avatar asked Oct 11 '25 23:10

Shitta 25


1 Answers

Assuming your trying to use HTMLImageElement: Image() constructor And not a external package.

Try installing @types/node,

npm install --save @types/node
// or
yarn add -D @types/node
like image 113
aeXuser264 Avatar answered Oct 14 '25 16:10

aeXuser264



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!