Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument of type { [x: string]: Blob; } is not assignable to parameter of type Record<string, ClipboardItemData> #46116

Closed
Bahman-66 opened this issue Sep 28, 2021 · 6 comments
Labels
Fixed A PR has been merged for this issue

Comments

@Bahman-66
Copy link

Bahman-66 commented Sep 28, 2021

lib Update Request

Configuration Check

My compilation target is ES2017 and my lib is ES2018.

Missing / Incorrect Definition

error TS2345: Argument of type '{ [x: string]: Blob; }' is not assignable to parameter of type 'Record<string, ClipboardItemData>'.
  'string' index signatures are incompatible.
    Type 'Blob' is missing the following properties from type 'Promise<ClipboardItemDataType>': then, catch, finally, [Symbol.toStringTag]

Sample Code

graphicDiv.addEventListener(
  'dragend',
  (event) => {
    const canvas = <HTMLCanvasElement>document.getElementById('canvas');
    canvas.toBlob((blob) => {
      if (blob) {
        let data = [new ClipboardItem({ [blob.type]: blob })];

        navigator.clipboard.write(data).then(
          function () {},
          function (err) {}
        );
      }
    });
  },
  false
);   

Documentation Link

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard

@IllusionMH
Copy link
Contributor

This matches definition of ClipboardItemData in https://www.w3.org/TR/clipboard-apis/#typedefdef-clipboarditemdata

Related discussion is w3c/clipboard-apis#102
However it's not clear for me why IDL "implies" that non-promise value is OK

@Bahman-66
Copy link
Author

I manipulated the lib file so ClipboardItem constructor accepted any types for items and also the Clipbard.write method accept any parameter the results is as follow:

linux machine

  • chrome

TypeError: Failed to construct 'ClipboardItem': Failed to convert value to 'Blob'.

  • firefox

ReferenceError: ClipboardItem is not defined

-edge beta version
successfully copied the image from blob to clipboard

windows machine

all of them fails similar to firefox and chrome on linux

@andrewbranch
Copy link
Member

Can you show exactly what change you are proposing to make to what definition? I’m finding this kind of hard to follow without going and looking up a bunch of stuff.

@IllusionMH
Copy link
Contributor

I think changes are already in place: error in 4.4.3 and works in Nightly
Previously argument was

Record<string, ClipboardItemData>

but in Nightly it's

Record<string, ClipboardItemDataType | PromiseLike<ClipboardItemDataType>>

@IllusionMH
Copy link
Contributor

It was fixed in microsoft/TypeScript-DOM-lib-generator#1102

And there is further PR to leave only Blob at this moment microsoft/TypeScript-DOM-lib-generator#1139

I believe this issue can be closed (but I'm not reporter).

@andrewbranch
Copy link
Member

Thanks @IllusionMH!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants