From 034679e9345a8a3abd894e656570fdd8973bcba5 Mon Sep 17 00:00:00 2001 From: David Broder-Rodgers Date: Mon, 18 Dec 2017 12:41:57 +0000 Subject: [PATCH 1/2] Add typings for cordova-universal-links-plugin --- .../cordova-universal-links-plugin-tests.ts | 16 +++++++++++++ .../cordova-universal-links-plugin/index.d.ts | 24 +++++++++++++++++++ .../tsconfig.json | 24 +++++++++++++++++++ .../tslint.json | 3 +++ 4 files changed, 67 insertions(+) create mode 100644 types/cordova-universal-links-plugin/cordova-universal-links-plugin-tests.ts create mode 100644 types/cordova-universal-links-plugin/index.d.ts create mode 100644 types/cordova-universal-links-plugin/tsconfig.json create mode 100644 types/cordova-universal-links-plugin/tslint.json diff --git a/types/cordova-universal-links-plugin/cordova-universal-links-plugin-tests.ts b/types/cordova-universal-links-plugin/cordova-universal-links-plugin-tests.ts new file mode 100644 index 0000000000..e16254312b --- /dev/null +++ b/types/cordova-universal-links-plugin/cordova-universal-links-plugin-tests.ts @@ -0,0 +1,16 @@ +const newsEventname = 'openNewsListPage'; +universalLinks.subscribe(newsEventname, onNewsListPageRequested); + +function onNewsListPageRequested(eventData: EventData) { + alert('Did launch application with news link: ' + eventData.url); +} + +universalLinks.unsubscribe('openNewsListPage'); + +window.universalLinks.subscribe(null, onOtherLinkRequested); + +function onOtherLinkRequested(eventData: EventData) { + alert('Did launch application with other link: ' + eventData.url); +} + +window.universalLinks.unsubscribe(null); diff --git a/types/cordova-universal-links-plugin/index.d.ts b/types/cordova-universal-links-plugin/index.d.ts new file mode 100644 index 0000000000..6b29c1a37e --- /dev/null +++ b/types/cordova-universal-links-plugin/index.d.ts @@ -0,0 +1,24 @@ +// Type definitions for cordova-universal-links-plugin 1.2 +// Project: https://github.com/nordnet/cordova-universal-links-plugin#readme +// Definitions by: David Broder-Rodgers +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface EventData { + url: string; + scheme: string; + host: string; + path: string; + params: { [key: string]: string }; + hash: string; +} + +interface UniversalLinks { + subscribe(eventName: string | null, callback: (data: EventData) => void): void; + unsubscribe(eventName: string | null): void; +} + +interface Window { + universalLinks: UniversalLinks; +} + +declare var universalLinks: UniversalLinks; diff --git a/types/cordova-universal-links-plugin/tsconfig.json b/types/cordova-universal-links-plugin/tsconfig.json new file mode 100644 index 0000000000..69322a9265 --- /dev/null +++ b/types/cordova-universal-links-plugin/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cordova-universal-links-plugin-tests.ts" + ] +} diff --git a/types/cordova-universal-links-plugin/tslint.json b/types/cordova-universal-links-plugin/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/cordova-universal-links-plugin/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} From a7c9e3bb8a327a4ba7282cddb137d74c64c20959 Mon Sep 17 00:00:00 2001 From: David Broder-Rodgers Date: Mon, 18 Dec 2017 13:55:46 +0000 Subject: [PATCH 2/2] Update typings to use namespace --- .../cordova-universal-links-plugin-tests.ts | 8 +++--- .../cordova-universal-links-plugin/index.d.ts | 28 ++++++++----------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/types/cordova-universal-links-plugin/cordova-universal-links-plugin-tests.ts b/types/cordova-universal-links-plugin/cordova-universal-links-plugin-tests.ts index e16254312b..1a6981b2e9 100644 --- a/types/cordova-universal-links-plugin/cordova-universal-links-plugin-tests.ts +++ b/types/cordova-universal-links-plugin/cordova-universal-links-plugin-tests.ts @@ -1,16 +1,16 @@ const newsEventname = 'openNewsListPage'; universalLinks.subscribe(newsEventname, onNewsListPageRequested); -function onNewsListPageRequested(eventData: EventData) { +function onNewsListPageRequested(eventData: universalLinks.EventData) { alert('Did launch application with news link: ' + eventData.url); } universalLinks.unsubscribe('openNewsListPage'); -window.universalLinks.subscribe(null, onOtherLinkRequested); +universalLinks.subscribe(null, onOtherLinkRequested); -function onOtherLinkRequested(eventData: EventData) { +function onOtherLinkRequested(eventData: universalLinks.EventData) { alert('Did launch application with other link: ' + eventData.url); } -window.universalLinks.unsubscribe(null); +universalLinks.unsubscribe(null); diff --git a/types/cordova-universal-links-plugin/index.d.ts b/types/cordova-universal-links-plugin/index.d.ts index 6b29c1a37e..98217a1b0a 100644 --- a/types/cordova-universal-links-plugin/index.d.ts +++ b/types/cordova-universal-links-plugin/index.d.ts @@ -3,22 +3,16 @@ // Definitions by: David Broder-Rodgers // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface EventData { - url: string; - scheme: string; - host: string; - path: string; - params: { [key: string]: string }; - hash: string; -} +declare namespace universalLinks { + function subscribe(eventName: string | null, callback: (data: EventData) => void): void; + function unsubscribe(eventName: string | null): void; -interface UniversalLinks { - subscribe(eventName: string | null, callback: (data: EventData) => void): void; - unsubscribe(eventName: string | null): void; + interface EventData { + url: string; + scheme: string; + host: string; + path: string; + params: { [key: string]: string }; + hash: string; + } } - -interface Window { - universalLinks: UniversalLinks; -} - -declare var universalLinks: UniversalLinks;