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

refactor: Migrate to typescript #95

Closed
wants to merge 20 commits into from

Conversation

g-dimitry
Copy link
Collaborator

Hello Guys,

I've successfully migrated all the code base to Typescript. My philosophy was to try as much as I can to make this a minor release (as @mikehardy stated). You'll see I have added three TODO comments (search for "TODO: [TS Migration]:"). Those are changes that need to be discussed and addressed maybe in the next major release.

To test the compatibility of both the new types and the old types:

  1. I reverted the commit removing the old types
  2. Created an index.ts file at the root of the repo
  3. Imported both new and old types the same way so: import * as oldTypes from 'react-native-fbsdk-next' and import * as newTypes from './src'
  4. Created a new constant with the same type as the oldTypes' import and assign to it the newTypes: const o: typeof oldTypes = newTypes;
  5. Solved all differences until the compiler had no errors. (All changes are marked by a "TODO: [TS Migration]:" comment)

I guess we need to test it on a running project first to check it works with a JS project & a TS project in development and release modes.

If anybody can test the above and confirm it's not breaking it would be awesome.

Looking forward to your comments.

@g-dimitry g-dimitry changed the title Migrate to typescript refactor: Migrate to typescript Sep 12, 2021
@g-dimitry
Copy link
Collaborator Author

And of course the eslint/prettier configurations should be changed.

@g-dimitry
Copy link
Collaborator Author

I just changed the Eslint configuration but I had to change A LOT of code that may break old code so I guess the best way to do this is to agree on what to do with this migration: should we release a minor release and then a new major release with the linted and clean code (that may break some old false types) ?

@mikehardy
Copy link
Collaborator

  1. this sounds amazing!
  2. with sincere apologies I'm traveling until the 21st and then will likely have a backlog of project work to slash through before I can spin through volunteer repos so perhaps someone else can give this a spin 🙏 ? Otherwise it'll have to sit for a little bit ...

@mikehardy
Copy link
Collaborator

(I can say philosophically just in my opinion I think a major is probably warranted, the goal was just for it to be easiest possible migration for any module users, as a general courtesy - I'm guessing it's probably walking that fine line well just based on how you're describing it though I admit I haven't looked)

@thebergamo
Copy link
Owner

I was considering picking up this task together with upgrading Facebook SDK.
Can't thank you more @g-dimitry for pick this challenge of migration to TS.
Let me review it o/

Copy link
Owner

@thebergamo thebergamo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are few questions of mine also inside some points, specially this name: string | undefined as I believe we should stick to a pattern in this case using name?: string as in most cases would have similar effect.

Once again thanks for this PR o/

src/FBAccessToken.ts Outdated Show resolved Hide resolved
@@ -131,7 +133,7 @@ module.exports = {
logEvent(eventName: string, ...args: Array<number | Params>) {
let valueToSum = 0;
if (typeof args[0] === 'number') {
valueToSum = args.shift();
valueToSum = args.shift() as number;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of using ’as’ here, you could use ’Number(args.shift()’
What do you think?

Comment on lines 56 to 57
// TODO: [TS Migration]: Added default value to fix type definitions. Discuss before merging.
this.batchCallback = () => {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the case here to just use this.batchCallback?.() and then you won't need to put a default value here?
But either way having a default noop here seems fine to me.

DefaultAudience,
LoginBehaviorAndroid,
LoginResult,
LoginTracking,
} from './FBLoginManager';

type Event = Object;
type TooltipBehaviorIOS = 'auto' | 'force_display' | 'disable';
export type Event = any;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we be a bit more strict here?

src/FBProfile.ts Outdated
@@ -73,17 +70,18 @@ class FBProfile {
this.linkURL = profileMap.linkURL;
this.imageURL = profileMap.imageURL;
this.userID = profileMap.userID;
this.email = Platform.OS === 'android' ? null : profileMap.email;
// TODO: [TS Migration]: Value should be undefined. Discuss before merging.
this.email = Platform.OS === 'android' ? null as unknown as undefined : profileMap.email;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we could just mark email: string? | null and we can avoid this unknown type

src/index.ts Show resolved Hide resolved
@g-dimitry
Copy link
Collaborator Author

@thebergamo I'll finalize this on Saturday and I'll be sure to specify all breaking changes and tag you to discuss before merging. Thank you for the collaboration invitation, I'm very excited to help 😄

@thebergamo
Copy link
Owner

@g-dimitry i guess you would need to rebase as some new feature is added :)

@g-dimitry
Copy link
Collaborator Author

@thebergamo Unfortunately yes, Sorry for being late, Fell horribly ill. I guess I'll merge master into my branch it would be easier as I have 18 commits which will be a nightmare to rebase.

@thebergamo
Copy link
Owner

That's ok mate, your health is much more important o/ get great recovery 😃

@stale
Copy link

stale bot commented Dec 14, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Dec 14, 2021
@rnike
Copy link
Collaborator

rnike commented Dec 16, 2021

Just saw this before making the new implementation, does this need help? Maybe I can help complete this before implementing the new feature.

@stale stale bot removed the wontfix This will not be worked on label Dec 16, 2021
@mikehardy
Copy link
Collaborator

@mike this one really needs help - yes! It would be fantastic to have this be in typescript and I don't believe the library has moved on that far since it was initially begun here

@rnike
Copy link
Collaborator

rnike commented Dec 16, 2021

okay let me take a look at it

@rnike
Copy link
Collaborator

rnike commented Dec 29, 2021

Commits in this pr have been merged in #160, thanks for all the works.

@rnike rnike closed this Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants