Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added .d.ts file, so lib can be used in typescript react-native projects #4

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
41 changes: 41 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Module d.ts file

// Enables using module in typescript react-native projects,
// with editor auto-complete and type-validation (in VS Code)

// See:
// 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";

interface BarometerPayload { // See module README for field descriptions
timestamp:number,
pressure:number,
altitudeASL:number,
altitude:number,
relativeAltitude:number,
verticalSpeed:number,
};

type BarometerWatchCallbackFn = (payload:BarometerPayload) => void;

declare namespace Barometer { // See module README for function descriptions
function isSupported(): Promise<boolean>;
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;