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

Add TypeScript declarations to app-media. #48

Closed
wants to merge 4 commits into from
Closed

Conversation

TimvdLippe
Copy link

@TimvdLippe TimvdLippe commented Mar 18, 2018

This PR adds TypeScript declarations generated by https://github.com/Polymer/gen-typescript-declarations/

These declarations can be re-generated by running npm run update-types.

Tracker: https://github.com/Polymer/gen-typescript-declarations/issues/79

directories:
- node_modules
env:
global: []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not have the sauce-credentials.json file, so I was not able to generate these keys

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cc @azakus

* [here](https://w3c.github.io/mediacapture-image/##photosettings-section).
*/
readonly photoSettings: PhotoSettings;
fillLightMode: Polymer.AppMedia.FillLightMode|null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a type need to be generated for Polymer.AppMedia.FillLightMode?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aomarks I added the @namespace for Polymer.AppMedia, but it does not seem to detect that the other modes are also added to this namespace. Do you maybe know what is going wrong here?

readonly trackConstraints: MediaTrackConstraints;
whiteBalanceMode: string|null|undefined;
colorTemperature: number|null|undefined;
exposureMode: Polymer.AppMedia.MeteringMode|null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a type need to be generated for Polymer.AppMedia.MeteringMode?

*
* @returns Promise<Blob>
*/
takePhoto(): any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type seems wrong...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, should be @return

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both forms are accepted by closure compiler

Copy link
Contributor

@aomarks aomarks Mar 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, both are valid. I used @returns in the generator (when emitting documentation for the return type if there is any) because it seemed to be the canonical form for JSDoc (http://usejsdoc.org/tags-returns.html), although for Closure the canonical form is @return (https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#return-type-description), and that's what we use most of the time in the elements, so I now I'd prefer @return. But it didn't seem worth the churn of rewriting all these files over that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual problem here and below is that the source is missing curly braces around the type: @return {Promise<Blob>} (@returns would also work).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and... that would be @return {!Promise<!Blob>} because object types in Closure are nullable by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification @aomarks 🍻

@TimvdLippe would you be willing to fix the source annotation as part of this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will push an update tomorrow

*
* @returns Promise<ImageBitmap>
*/
grabFrame(): any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type seems wrong too

@aomarks aomarks changed the title Automatic cleanup! Add TypeScript declarations to app-media. Mar 18, 2018
/**
* An ImageCapture instance associated with the selected video track.
*/
readonly imageCapture: ImageCapture|null;
Copy link
Contributor

@aomarks aomarks Mar 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the ImageCapture type is defined in the TypeScript standard libs, so this shouldn't compile. We could define it by manually writing an extra-types.d.ts and including it with addReferences in gen-tsd.json, or ignore it by putting "renameTypes": {"ImageCapture": "any"} in the config file.

Copy link
Contributor

@cdata cdata Mar 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I contributed the closure types for this constructor and its related settings object to the closure externs. Would it be possible to make use of generated types based on that somehow?

Alternatively, would it be possible to make a similar contribution to the TypeScript standard library?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think we should upstream this into the lib.dom.d.ts typings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great. I wouldn't be opposed to doing the any rename for now since getting those into TS could take a while.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to see a first step as part of this change; maybe file an issue?

Copy link
Contributor

@cdata cdata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Some TODO before we merge:

  • It would be nice to see an issue filed somewhere related to the typings for ImageCapture and related interfaces.
  • @azakus to comment on getting the .travis.yml set up correctly

@TimvdLippe
Copy link
Author

I am closing this PR. We can autogenerate a new one later once the above issues are resolved.

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

Successfully merging this pull request may close these issues.

None yet

4 participants