Skip to content

"postMessage" declartion in 'lib.dom.d.ts' may have a little problem #30042

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

Closed
asurance opened this issue Feb 22, 2019 · 8 comments
Closed

"postMessage" declartion in 'lib.dom.d.ts' may have a little problem #30042

asurance opened this issue Feb 22, 2019 · 8 comments
Assignees
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript

Comments

@asurance
Copy link

asurance commented Feb 22, 2019

TypeScript Version: 3.3.3

  • postMessage declartion in lib.dom.d.ts is
declare function postMessage(message: any, targetOrigin: string, transfer?: Transferable[]): void;

Its second parameter targetOrigin is set as a must.
But I found samples on MDN about postMessage don't pass it.
There may lack a ? after targetOrigin.
When I set use strict of comile options true and don't pass targetOrigin, compiler will warn me ,which makes me X﹏X.

@AviVahl
Copy link

AviVahl commented Feb 22, 2019

Indeed optional according to the living "whatwg" specs.

https://html.spec.whatwg.org/multipage/web-messaging.html#posting-messages

"A target origin can be specified using the targetOrigin member of options. If not provided, it defaults to "/". This default restricts the message to same-origin targets only."

The fix probably needs to come from https://github.com/Microsoft/TSJS-lib-generator

@asurance
Copy link
Author

OK,Thank you.

@AviVahl
Copy link

AviVahl commented Feb 22, 2019

The relevant location, I think, is:
https://github.com/Microsoft/TSJS-lib-generator/blob/master/inputfiles/overridingTypes.json#L474

or, if master changes and the line isn't relevant, open overridingTypes.json and search for postMessage.

@sandersn
Copy link
Member

sandersn commented Apr 4, 2019

Actually, as @saschanaz points out, https://html.spec.whatwg.org/multipage/window-object.html#the-window-object:dom-window-postmessage shows that the parameter targetOrigin is required. When you provide an options object instead, the options object has an optional property named targetOrigin.

@AviVahl
Copy link

AviVahl commented Apr 6, 2019

@saschanaz @sandersn could you please check it out again? The docs you linked to say:

  void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);
  void postMessage(any message, optional WindowPostMessageOptions options);

which means postMessage([anything]) is a valid call. Perhaps the real issue is the types missing the overloaded signature (that has the optional options object).

@sandersn
Copy link
Member

sandersn commented Apr 8, 2019

@AviVahl I think @saschanaz fixed this in microsoft/TypeScript-DOM-lib-generator#679. Mind taking a look to see if that's the case?

@AviVahl
Copy link

AviVahl commented Apr 8, 2019

@sandersn issue does seem to be fixed in @saschanaz's PR.
you guys are awesome.

@sandersn
Copy link
Member

sandersn commented Apr 8, 2019

All thanks go to @saschanaz ! I am just a newbie in this space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants