add sharedworker/SharedWorker.d.ts

This commit is contained in:
Toshiya Nakakura
2014-12-11 19:51:28 +09:00
parent 1fb0d8c3e3
commit 9f572e72fb
2 changed files with 38 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
///<reference path="SharedWorker.d.ts" />
var worker_with_name = new SharedWorker('worker.js', "worker");
var worker = new SharedWorker('worker.js');
worker.port.onmessage = function(e) {
console.log(e);
};
+29
View File
@@ -0,0 +1,29 @@
// Type definitions for SharedWorker
// Project: http://www.w3.org/TR/workers/
// Definitions by: Toshiya Nakakura <https://github.com/nakakura>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module SharedWorker {
interface AbstractWorker extends EventTarget {
onerror: (ev: ErrorEvent) => any;
}
export interface SharedWorker extends AbstractWorker {
/**
* the value it was assigned by the object's constructor.
* It represents the MessagePort for communicating with the shared worker.
* @type {MessagePort}
*/
port: MessagePort;
}
}
declare var SharedWorker: {
prototype: SharedWorker.SharedWorker;
/***
*
* @param {string} stringUrl Pathname to JavaScript file
* @param {string} name Name of the worker to execute
*/
new (stringUrl: string, name?: string): SharedWorker.SharedWorker;
};