From 1b6b6be9e4a9b2142301ffe4b20fc6911a443c0a Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 08:27:28 -0800 Subject: [PATCH 01/11] Attempt 1 - adding a d ts file --- index.d.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..7ff07fe --- /dev/null +++ b/index.d.ts @@ -0,0 +1 @@ +declare module "react-native-barometer"; From 04394c37885c54e2af33ab62f294c9181bc8fb17 Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 08:54:27 -0800 Subject: [PATCH 02/11] update index.d.ts --- index.d.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.d.ts b/index.d.ts index 7ff07fe..da65084 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1 +1,15 @@ +//import Barometer from "." + declare module "react-native-barometer"; + +interface IBarometer { + watch: (watchCallbackFn:Function) => number, + clearWatch: (watchID:number) => void, + stopObserving: () => void, + isSupported: () => Promise, + setInterval: (interval:number) => void, + setLocalPressure: (pressure:number) => void, +} + +declare const Barometer:IBarometer; +export default Barometer; \ No newline at end of file From e3a594530f63a8d9d0a77bc47a01145986c33ad4 Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 09:48:35 -0800 Subject: [PATCH 03/11] updated d ts file --- index.d.ts | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index da65084..7683e86 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,15 +1,50 @@ -//import Barometer from "." +// Module d.ts file; enables this module to be used +// in typescript react-native projects + +// If keeping the interface below up-to-date proves +// to be a nuissance, options are: +// +// * Comment out everything below except the "declare module..." line +// (which enables this module to be used in typescript +// react-native projects). Cons: You lose auto-complete and +// type-checking in VS Code, but, if the types defined by +// the interface below aren't there - they can't be *wrong*. +// +// * Re-create this module using create-react-native-library, +// choosing typescript, and java/obj-c. See: +// https://reactnative.dev/docs/native-modules-setup, +// + +// See: +// https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html +// https://stackoverflow.com/a/51355583 declare module "react-native-barometer"; +interface Payload { // See README for descriptions + timestamp:number, + pressure:number, + altitudeASL:number, + altitude:number, + relativeAltitude:number, + verticalSpeed:number, +}; + +type WatchCallbackFn = (payload:Payload) => number; + interface IBarometer { - watch: (watchCallbackFn:Function) => number, + watch: WatchCallbackFn, clearWatch: (watchID:number) => void, stopObserving: () => void, isSupported: () => Promise, setInterval: (interval:number) => void, setLocalPressure: (pressure:number) => void, -} +}; declare const Barometer:IBarometer; + +export { + Barometer +}; + export default Barometer; \ No newline at end of file From 1ef0df742e8456df6045a74ead454a7a3111f8f8 Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 09:52:33 -0800 Subject: [PATCH 04/11] Clean up comments --- index.d.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/index.d.ts b/index.d.ts index 7683e86..74ec07c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,20 +1,6 @@ -// Module d.ts file; enables this module to be used +// Module d.ts file; enables using this module // in typescript react-native projects -// If keeping the interface below up-to-date proves -// to be a nuissance, options are: -// -// * Comment out everything below except the "declare module..." line -// (which enables this module to be used in typescript -// react-native projects). Cons: You lose auto-complete and -// type-checking in VS Code, but, if the types defined by -// the interface below aren't there - they can't be *wrong*. -// -// * Re-create this module using create-react-native-library, -// choosing typescript, and java/obj-c. See: -// https://reactnative.dev/docs/native-modules-setup, -// - // See: // https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html // https://stackoverflow.com/a/51355583 From 49816100c73b9a868409f334779fef2b5a59614b Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 09:58:31 -0800 Subject: [PATCH 05/11] Updated index.d.ts --- index.d.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 74ec07c..bd079d0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,7 +7,7 @@ declare module "react-native-barometer"; -interface Payload { // See README for descriptions +interface BarometerPayload { // See README for descriptions timestamp:number, pressure:number, altitudeASL:number, @@ -16,7 +16,7 @@ interface Payload { // See README for descriptions verticalSpeed:number, }; -type WatchCallbackFn = (payload:Payload) => number; +type WatchCallbackFn = (payload:BarometerPayload) => number; interface IBarometer { watch: WatchCallbackFn, @@ -30,7 +30,8 @@ interface IBarometer { declare const Barometer:IBarometer; export { - Barometer + Barometer, + BarometerPayload }; export default Barometer; \ No newline at end of file From 66b1ef6bbb7864ffe17da28d522ee8373f81fa5a Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 10:25:50 -0800 Subject: [PATCH 06/11] Updated index.d.ts --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index bd079d0..60bd789 100644 --- a/index.d.ts +++ b/index.d.ts @@ -19,7 +19,7 @@ interface BarometerPayload { // See README for descriptions type WatchCallbackFn = (payload:BarometerPayload) => number; interface IBarometer { - watch: WatchCallbackFn, + watch: (watchCallbackFn:WatchCallbackFn) => number, clearWatch: (watchID:number) => void, stopObserving: () => void, isSupported: () => Promise, From fb17635936fa19fe17a88fac6198ed210f15cf6c Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 10:33:17 -0800 Subject: [PATCH 07/11] Updated index.d.ts again --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 60bd789..120877f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -16,7 +16,7 @@ interface BarometerPayload { // See README for descriptions verticalSpeed:number, }; -type WatchCallbackFn = (payload:BarometerPayload) => number; +type WatchCallbackFn = (payload:BarometerPayload) => void; interface IBarometer { watch: (watchCallbackFn:WatchCallbackFn) => number, From ea5b420581f56debfa920a9a93d40e4cbe465769 Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 10:37:20 -0800 Subject: [PATCH 08/11] Exporting WatchCallbackFn --- index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 120877f..dbb26fb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -31,7 +31,8 @@ declare const Barometer:IBarometer; export { Barometer, - BarometerPayload + BarometerPayload, + WatchCallbackFn }; export default Barometer; \ No newline at end of file From 0e9066145bf02046c161150b891b684a057c9ca2 Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 11:01:29 -0800 Subject: [PATCH 09/11] Working on index.d.ts --- index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.d.ts b/index.d.ts index dbb26fb..6bc7e82 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,6 +7,8 @@ declare module "react-native-barometer"; +import Barometer from "."; + interface BarometerPayload { // See README for descriptions timestamp:number, pressure:number, From 6468020b5ea7266b11076432dbc236d1f8f7d2b6 Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 11:10:49 -0800 Subject: [PATCH 10/11] Working on index.d.ts --- index.d.ts | 69 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6bc7e82..ba08b91 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,11 +5,43 @@ // https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html // https://stackoverflow.com/a/51355583 -declare module "react-native-barometer"; +// declare module "react-native-barometer"; + +// import Barometer from "."; + +// interface BarometerPayload { // See README for field descriptions +// timestamp:number, +// pressure:number, +// altitudeASL:number, +// altitude:number, +// relativeAltitude:number, +// verticalSpeed:number, +// }; + +// type WatchCallbackFn = (payload:BarometerPayload) => void; -import Barometer from "."; +// interface IBarometer { +// watch: (watchCallbackFn:WatchCallbackFn) => number, +// clearWatch: (watchID:number) => void, +// stopObserving: () => void, +// isSupported: () => Promise, +// setInterval: (interval:number) => void, +// setLocalPressure: (pressure:number) => void, +// }; -interface BarometerPayload { // See README for descriptions +// declare const Barometer:IBarometer; + +// export { +// Barometer, +// BarometerPayload, +// WatchCallbackFn +// }; + +// export default Barometer; + +declare module "react-native-barometer"; + +interface BarometerPayload { // See README for field descriptions timestamp:number, pressure:number, altitudeASL:number, @@ -18,23 +50,14 @@ interface BarometerPayload { // See README for descriptions verticalSpeed:number, }; -type WatchCallbackFn = (payload:BarometerPayload) => void; - -interface IBarometer { - watch: (watchCallbackFn:WatchCallbackFn) => number, - clearWatch: (watchID:number) => void, - stopObserving: () => void, - isSupported: () => Promise, - setInterval: (interval:number) => void, - setLocalPressure: (pressure:number) => void, -}; - -declare const Barometer:IBarometer; - -export { - Barometer, - BarometerPayload, - WatchCallbackFn -}; - -export default Barometer; \ No newline at end of file +type BarometerWatchCallbackFn = (payload:BarometerPayload) => void; + +export default Barometer; +declare namespace Barometer { + function watch(success: BarometerWatchCallbackFn): number; + function clearWatch(watchID: any): void; + function stopObserving(): void; + function isSupported(): Promise; + function setInterval(interval: any): void; + function setLocalPressure(pressure: any): void; +} \ No newline at end of file From 8ab4bbe70e2f7d5a8039eb4948678da06f56eb0a Mon Sep 17 00:00:00 2001 From: kleydon Date: Fri, 13 Jan 2023 12:45:28 -0800 Subject: [PATCH 11/11] Update .d.ts file --- index.d.ts | 70 +++++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/index.d.ts b/index.d.ts index ba08b91..cebbb20 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,47 +1,19 @@ -// Module d.ts file; enables using this module -// in typescript react-native projects +// Module d.ts file + +// Enables using module in typescript react-native projects, +// with editor auto-complete and type-validation (in VS Code) // See: -// https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html +// Typescript docs: +// https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html +// Typescript Playground, for automatic generation of .d.ts file from .js: +// https://www.typescriptlang.org/play?filetype=js&useJavaScript=true#code/Q +// Simplest approach: // https://stackoverflow.com/a/51355583 -// declare module "react-native-barometer"; - -// import Barometer from "."; - -// interface BarometerPayload { // See README for field descriptions -// timestamp:number, -// pressure:number, -// altitudeASL:number, -// altitude:number, -// relativeAltitude:number, -// verticalSpeed:number, -// }; - -// type WatchCallbackFn = (payload:BarometerPayload) => void; - -// interface IBarometer { -// watch: (watchCallbackFn:WatchCallbackFn) => number, -// clearWatch: (watchID:number) => void, -// stopObserving: () => void, -// isSupported: () => Promise, -// setInterval: (interval:number) => void, -// setLocalPressure: (pressure:number) => void, -// }; - -// declare const Barometer:IBarometer; - -// export { -// Barometer, -// BarometerPayload, -// WatchCallbackFn -// }; - -// export default Barometer; - declare module "react-native-barometer"; -interface BarometerPayload { // See README for field descriptions +interface BarometerPayload { // See module README for field descriptions timestamp:number, pressure:number, altitudeASL:number, @@ -52,12 +24,18 @@ interface BarometerPayload { // See README for field descriptions type BarometerWatchCallbackFn = (payload:BarometerPayload) => void; +declare namespace Barometer { // See module README for function descriptions + function isSupported(): Promise; + function setInterval(interval: number): void; + function setLocalPressure(pressure: number): void; + function watch(success: BarometerWatchCallbackFn): number; + function clearWatch(watchID: any): void; + function stopObserving(): void; +} + +export { + BarometerPayload, + BarometerWatchCallbackFn +}; + export default Barometer; -declare namespace Barometer { - function watch(success: BarometerWatchCallbackFn): number; - function clearWatch(watchID: any): void; - function stopObserving(): void; - function isSupported(): Promise; - function setInterval(interval: any): void; - function setLocalPressure(pressure: any): void; -} \ No newline at end of file