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

WebIDL parameter Promise type not converted when in a nested type, e.g. ClipboardItemData #999

Closed
wffurr opened this issue Apr 14, 2021 · 3 comments

Comments

@wffurr
Copy link

wffurr commented Apr 14, 2021

WebIDL has an implicit conversion mechanism for an ECMAScript value V into an IDL Promise<T> type. This means that any function defined in WebIDL that accepts a Promise<T> implicitly accepts T|Promise<T>.

However, the generated TypeScript typings for a WebIDL function that accepts a Promise<T> argument only have the type Promise<T>, and not the non-Promise T type. The generated typings should have T|Promise<T>.

e.g. in https://w3c.github.io/clipboard-apis/#clipboard-interface, the ClipboardItem constructor takesClipboardItemData as the values in the items record. The generated typings for that type should be string|Blobl|Promise<string|Blob> but instead it's just Promise<string|Blob>.

See wffurr@9c8bc4b for an example.

@wffurr
Copy link
Author

wffurr commented Apr 14, 2021

I see there's some code to handle this already:

p = { name: p.name, type: [p.subtype!, p] };

It works great for the Payment Request API:

show(detailsPromise: PaymentDetailsUpdate | Promise<PaymentDetailsUpdate>): Promise<PaymentResponse>;

But not for ClipboardItemData because it's in the value position of a record type that is itself a parameter to a function. The recursion in paramsToString would have to propagate the knowledge that a parameter is being converted and conditionally modify any Promise types that are passed in to the browser but not ones come back from the browser, e.g. return types of callback arguments but not parameter types of callback arguments.

@wffurr wffurr changed the title WebIDL methods implicitly convert values to Promise types WebIDL parameter Promise type not converted when in a nested type, e.g. ClipboardItemData Apr 14, 2021
@saschanaz
Copy link
Contributor

#1102

@github-actions close

@github-actions
Copy link
Contributor

Closing because @saschanaz is one of the code-owners of this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants