Skip to content

[service_worker_api] remove fetch API interfaces and add new APIs - #13664

Merged
16 commits merged into
DefinitelyTyped:masterfrom
dolphin-wood:master
Jan 2, 2017
Merged

16 commits merged into
DefinitelyTyped:masterfrom
dolphin-wood:master

Conversation

@dolphin-wood

@dolphin-wood dolphin-wood commented Jan 1, 2017 •

Copy link
Copy Markdown
Contributor

This PR removed the incompatible fetch API interfaces in respect to #12476 and #12582, and added new API interfaces as per Sercive Worker Draft.

@mohsen1 we have no choice but to merge the ServiceWorkerGlobalScope interface into Window, since there's no other global scopes. Meanwhile, some interfaces in ServiceWorkerGlobalScope, eg. onmessage, are not compatible with those in Window, I don't know if there are some workarounds other than rewriting them like:

interface ServiceWorkerGlobalScope {
    // onmessage: (messageevent: ExtendableMessageEvent) => void;
    onmessage: (messageevent: MessageEvent) => void;
}

Update: I found that lib.webworker.d.ts is using a /// <reference no-default-lib="true"/> directive to exclude the default lib, however when I tried adding the same directive to this lib, I got tons of type missing errors 😢.

  • Make your PR against the master branch.
  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run tsc without errors.
  • Run npm run lint package-name if a tslint.json is present.

Changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: https://www.w3.org/TR/service-workers
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "../tslint.json" }.

@dt-bot

dt-bot commented Jan 1, 2017

Copy link
Copy Markdown
Member

service_worker_api/index.d.ts

to author (@tristancaron). Could you review this PR?
👍 or 👎?

Checklist

  • pass the Travis CI test?

@mohsen1 mohsen1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Might be a good time to add linting. (Add tslint.json with { "extends": "../tslint.json" }.)

@@ -1,3 +1,5 @@
/// <reference path="../whatwg-fetch/index.d.ts" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

/// <reference types="whatwg-fetch" />

Comment thread service_worker_api/index.d.ts Outdated
// TypeScript Version: 2.1

// <reference path="../es6-promise/es6-promise.d.ts" /> // REMOVED third "/" so this doesn't fire. Problem with duplicate Promises
// <reference path="../whatwg-fetch/index.d.ts" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

/// <reference types="whatwg-fetch" />

Comment thread service_worker_api/index.d.ts Outdated
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// TypeScript Version: 2.1

// <reference path="../es6-promise/es6-promise.d.ts" /> // REMOVED third "/" so this doesn't fire. Problem with duplicate Promises

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Delete

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Then Travis will fail with compilation errors :/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Was referring to the commented-out reference.

* push notification is received.
*
* @param [onpushevent]
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Jsdoc still indicates that the parameter is optional. (This is a good reason not to have redundant jsdoc annotations.)

@dolphin-wood

dolphin-wood commented Jan 2, 2017 •

Copy link
Copy Markdown
Contributor Author

@Andy-MS I just added "dt-header": false rule to tslint to pass the version lint, for there's no version for the service worker API. Will it be better to add a // tslint:disable-next-line dt-header annotation above the headers (I'm worried about breaking the format and, somehow, breaking the build process).

FYI:

// tslint:disable-next-line dt-header
// Type definitions for service_worker_api
// Project: https://developer.mozilla.org/fr/docs/Web/API/ServiceWorker_API
...

And I'm afraid I couldn't remove the TypeScript Version: 2.1 header now because I am using some features from ts2.1.

@ghost

ghost commented Jan 2, 2017

Copy link
Copy Markdown

For the header, I would just write 0.0 there. We have to publish under some version, after all, and 0.0 will be inferred anyway if you don't write it.

@dolphin-wood

Copy link
Copy Markdown
Contributor Author

@Andy-MS done.

@ghost

ghost commented Jan 2, 2017

Copy link
Copy Markdown

Thanks!

This pull request was closed.
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

Successfully merging this pull request may close these issues.

3 participants