Add type for react-native-permissions (#24793)

This commit is contained in:
Vincent Langlet
2018-04-09 18:58:52 +02:00
committed by Mohamed Hegazy
parent ad0637bfe3
commit 65f148de7d
4 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
// Type definitions for react-native-permissions 1.1
// Project: https://github.com/yonahforst/react-native-permissions
// Definitions by: Vincent Langlet <https://github.com/vincentlanglet>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined';
interface Rationale {
title: string;
message: string;
}
type CheckOptions = string | { type: string };
type RequestOptions = string | { type: string, rationale?: Rationale };
interface ReactNativePermissions {
canOpenSettings: () => Promise<boolean>;
openSettings: () => Promise<any>;
getTypes: () => string[];
check: (permission: string, options?: CheckOptions) => Promise<Status>;
request: (permission: string, options?: RequestOptions) => Promise<Status>;
checkMultiple: (permissions: string[]) => Promise<{ [key: string]: string }>;
}
declare const Permissions: ReactNativePermissions;
export default Permissions;

View File

@@ -0,0 +1,9 @@
import Permissions from 'react-native-permissions';
const firstType = Permissions.getTypes()[0];
Permissions.canOpenSettings().then();
Permissions.openSettings().then();
Permissions.check('geolocation').then();
Permissions.request('geolocation').then();
Permissions.checkMultiple(['geolocation', 'notification']).then();

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"react-native-permissions-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }