naoufal / react-native-touch-id

React Native authentication with the native Touch ID popup.
https://www.npmjs.com/package/react-native-touch-id
1.48k stars 477 forks source link

[Types] added namespace #214

Closed BenWildeman closed 5 years ago

BenWildeman commented 5 years ago

Added namespace to types so it's possible to override incorrect types in a declarations.d.ts file until the module is correctly patched

Edit: explanation https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-namespaces

in TypeScript, it's possible to merge namespaces so if I wanted to fix the BiometryType locally whilst I wait for the PR to be merged, I could have added the following to my declarations.d.ts which means other developers on my team would also have the patch:

declare module "react-native-touch-id" {
    namespace ReactNativeTouchID {
        type BiometryType: 'FaceID' | 'TouchID' | true;
    }

    const TouchID: {
        /**
         *
         * @param reason String that provides a clear reason for requesting authentication.
         * @param config Configuration object for more detailed dialog setup
         */
        authenticate(reason?: string, config?: ReactNativeTouchID.AuthenticateConfig);
        /**
         * 
         * @param config - Returns a `Promise` that rejects if TouchID is not supported. On iOS resolves with a `biometryType` `String` of `FaceID` or `TouchID`
         */
        isSupported(config?: ReactNativeTouchID.IsSupportedConfig): Promise<ReactNativeTouchID.BiometryType>;
    };

    export default TouchID;
}
BenWildeman commented 5 years ago

gah, can't override const in declarations so this kind of patch wouldn't work with this module

zibs commented 5 years ago

Can reopen if you get it working