From a790f39720e8522c8048388c777f10db1a56729b Mon Sep 17 00:00:00 2001 From: tsmalla Date: Thu, 21 Jun 2018 17:13:02 +0200 Subject: [PATCH 1/2] Add type declaration for react-native-background-timer --- .../react-native-background-timer/index.d.ts | 36 +++++++++++++++++++ .../react-native-background-timer-tests.ts | 31 ++++++++++++++++ .../tsconfig.json | 22 ++++++++++++ .../react-native-background-timer/tslint.json | 1 + 4 files changed, 90 insertions(+) create mode 100644 types/react-native-background-timer/index.d.ts create mode 100644 types/react-native-background-timer/react-native-background-timer-tests.ts create mode 100644 types/react-native-background-timer/tsconfig.json create mode 100644 types/react-native-background-timer/tslint.json diff --git a/types/react-native-background-timer/index.d.ts b/types/react-native-background-timer/index.d.ts new file mode 100644 index 0000000000..dc5a7b1638 --- /dev/null +++ b/types/react-native-background-timer/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for react-native-background-timer 2.0 +// Project: https://github.com/ocetnik/react-native-background-timer#readme +// Definitions by: Tjark Smalla +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + +/*~ You can declare types that are available via importing the module */ +export type IntervalId = number; +export type TimeoutId = number; + +/*~ You can declare properties of the module using const, let, or var */ +declare class BackgroundTimer { + + constructor(); + + start(delay?:number): any; + + stop(): void; + + runBackgroundTimer(callback: ()=>void, delay: number): void; + + backgroundClockMethod(callback: ()=>void, delay: number): void; + + stopBackgroundTimer(): void; + + setTimeout(callback: ()=>void, timeout: number): TimeoutId; + + clearTimeout(timeoutId: TimeoutId): void; + + setInterval(callback: ()=>void, timeout: number): IntervalId; + + clearInterval(intervalId: IntervalId): void; +} + +declare const _BackgroundTimer: BackgroundTimer; +export default _BackgroundTimer; \ No newline at end of file diff --git a/types/react-native-background-timer/react-native-background-timer-tests.ts b/types/react-native-background-timer/react-native-background-timer-tests.ts new file mode 100644 index 0000000000..6ee4334a8d --- /dev/null +++ b/types/react-native-background-timer/react-native-background-timer-tests.ts @@ -0,0 +1,31 @@ +// Tests taken from Examples at https://github.com/ocetnik/react-native-background-timer +import BackgroundTimer from 'react-native-background-timer'; + +BackgroundTimer.runBackgroundTimer(() => { + // do stuff + }, + 3000); + // rest of code will be performing for iOS on background too + BackgroundTimer.stopBackgroundTimer(); + +BackgroundTimer.start(); +// Do whatever you want incuding setTimeout; +BackgroundTimer.stop(); + +// Start a timer that runs continuous after X milliseconds +const intervalId = BackgroundTimer.setInterval(() => { + // this will be executed every 200 ms + // even when app is the the background +}, 200); + +// Cancel the timer when you are done with it +BackgroundTimer.clearInterval(intervalId); + +// Start a timer that runs once after X milliseconds +const timeoutId = BackgroundTimer.setTimeout(() => { + // this will be executed once after 10 seconds + // even when app is the the background +}, 10000); + +// Cancel the timeout if necessary +BackgroundTimer.clearTimeout(timeoutId); diff --git a/types/react-native-background-timer/tsconfig.json b/types/react-native-background-timer/tsconfig.json new file mode 100644 index 0000000000..d2faa0faf1 --- /dev/null +++ b/types/react-native-background-timer/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-native-background-timer-tests.ts" + ] +} diff --git a/types/react-native-background-timer/tslint.json b/types/react-native-background-timer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-background-timer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From d6af3047baeec3425b78539be17bc30dc5770b48 Mon Sep 17 00:00:00 2001 From: tsmalla Date: Thu, 21 Jun 2018 17:44:39 +0200 Subject: [PATCH 2/2] satisfy linter --- types/react-native-background-timer/index.d.ts | 14 ++++++-------- types/react-native-background-timer/tsconfig.json | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/types/react-native-background-timer/index.d.ts b/types/react-native-background-timer/index.d.ts index dc5a7b1638..7a64700595 100644 --- a/types/react-native-background-timer/index.d.ts +++ b/types/react-native-background-timer/index.d.ts @@ -3,34 +3,32 @@ // Definitions by: Tjark Smalla // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - /*~ You can declare types that are available via importing the module */ export type IntervalId = number; export type TimeoutId = number; /*~ You can declare properties of the module using const, let, or var */ declare class BackgroundTimer { - constructor(); - start(delay?:number): any; + start(delay?: number): any; stop(): void; - runBackgroundTimer(callback: ()=>void, delay: number): void; + runBackgroundTimer(callback: () => void, delay: number): void; - backgroundClockMethod(callback: ()=>void, delay: number): void; + backgroundClockMethod(callback: () => void, delay: number): void; stopBackgroundTimer(): void; - setTimeout(callback: ()=>void, timeout: number): TimeoutId; + setTimeout(callback: () => void, timeout: number): TimeoutId; clearTimeout(timeoutId: TimeoutId): void; - setInterval(callback: ()=>void, timeout: number): IntervalId; + setInterval(callback: () => void, timeout: number): IntervalId; clearInterval(intervalId: IntervalId): void; } declare const _BackgroundTimer: BackgroundTimer; -export default _BackgroundTimer; \ No newline at end of file +export default _BackgroundTimer; diff --git a/types/react-native-background-timer/tsconfig.json b/types/react-native-background-timer/tsconfig.json index d2faa0faf1..e4c1076050 100644 --- a/types/react-native-background-timer/tsconfig.json +++ b/types/react-native-background-timer/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../"