Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Convert JS code to TypeScript #9

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

thib92
Copy link

@thib92 thib92 commented Sep 3, 2019

Summary

Convert the index.js file to TypeScript, and provide types and interfaces for all options, enums and returned objects.

This is part of the plan described in #2.

TODO

  • Add types to SignInWithApple (with all enums and sub-types)
  • Add types to SignInWithAppleButton
  • Create a build script to export index.ts to index.js and index.d.ts (tsc with ES6 exports should be enough for now as the current JS code only exports as ES6 and no bundling is necessary)
  • Make sure everything is well exported when transpiled.

Test Plan

What's required for testing (prerequisites)?

  • A React-Native project already setup with TypeScript

What are the steps to reproduce (after prerequisites)?

  • Import this package and link it
  • Use all features and make sure no type errors are popping up
  • Make sure the module works as expected

Compatibility

(Not applicable)

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I mentioned this change in CHANGELOG.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)

@thib92
Copy link
Author

thib92 commented Sep 3, 2019

As far as I could read the Objective-C implementation (which means "barely"), only the requestAsync method is implemented on the SignInWithApple object. Therefore, I didn't make the typings for the other methods documented in the README.

@thib92
Copy link
Author

thib92 commented Sep 3, 2019

Also, is there a testing process already in place so that I can stick to it? How would I test the module in a blank project to make sure it works? Just point a package.json dependency to my work folder?

Add index.js to gitignore
Ignore delcaration file in git
Remove semicolons for interface declarations to avoid having them in the transpiled file
@thib92
Copy link
Author

thib92 commented Sep 3, 2019

I added a build script to the package.json, emitting an index.js file. I kept the target to ES6, but it can be changed depending on what you want to ship to NPM.

@thib92
Copy link
Author

thib92 commented Sep 3, 2019

Added the types for SignInWithAppleButton.

I've experimented with TypeScript namespace and module to have a better way of handling the enums attached to the object, but it seems quite complex.

I also tried using TypeScript enum, which is great since it provides both values and types, but since everything in this file is just types and interfaces declarations, and the actual "implementation" is done by NativeModules.RNCAppleAuthentication and requireNativeComponent, I can't really use them.

@thib92
Copy link
Author

thib92 commented Sep 5, 2019

@matt-oakes @vonovak I would love some feedback on this. I'm not super familiar with the native bridge, so maybe I'm doing a few things wrong.

Also, if there is a specific testing process, I'd love to hear about it to make sure I test this right.

@vonovak
Copy link
Contributor

vonovak commented Sep 6, 2019

@thib92 hi and thanks for you time! Please stand by for now, we're not sure at this point if we're going to keep this repo or rely on Expo for apple auth. Thanks!

@thib92
Copy link
Author

thib92 commented Sep 6, 2019

@vonovak thanks for the update. Please keep me posted 😄

@fbartho
Copy link

fbartho commented Sep 13, 2019

@vonovak we don’t have Expo in our app, so… I’d love to move forwards with this library, & TypeScript. How can I help?

(I’ve made native modules, and our app is in TypeScript, and I’ve been writing objective-c since 2006)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants