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

chore: assign TS migration #709

Merged

Conversation

radko93
Copy link
Contributor

@radko93 radko93 commented Sep 11, 2019

Summary:

Migrated assign.js and isValidPackageName.js to typescript. Related to #683
Is isValidPackageName used by external tool? Because it's not being used inside CLI so maybe we can remove it.

@thymikee
Copy link
Member

Looks like we can remove isValidPackageName, likely a leftover when refactoring init.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Looking good!

return acc;
}, {});
let descriptors = Object.keys(source).reduce(
(acc: {[k: string]: any}, key) => {
Copy link
Member

Choose a reason for hiding this comment

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

how about moving the type to initial value in second argument of reduce? also, please use "unknown" instead of "any"

Copy link
Contributor

@assuncaocharles assuncaocharles Sep 11, 2019

Choose a reason for hiding this comment

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

Maybe PropertyDescriptorMap it's a better fit than unknown?

(acc: PropertyDescriptorMap, key: string) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

New update using PropertyDescriptorMap. I had to add a safety check because getOwnPropertyDescriptor also returns undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also uknown does not work that great here because you cannot pass it to Object.defineProperties later on.

@radko93
Copy link
Contributor Author

radko93 commented Sep 11, 2019

Looks like we can remove isValidPackageName, likely a leftover when refactoring init.

Removed.

}
return acc;
},
{} as PropertyDescriptorMap,
Copy link
Contributor

@assuncaocharles assuncaocharles Sep 11, 2019

Choose a reason for hiding this comment

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

I guess it's more readable with the typing in the parameters?!?

(acc: PropertyDescriptorMap, key: string) => {

So you avoid the typecasting in the initial value as PropertyDescriptorMap

But it's just my opinion 🤔

What do you think, @thymikee and @radko93?

Copy link
Contributor Author

@radko93 radko93 Sep 11, 2019

Choose a reason for hiding this comment

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

IMO it's a bit also more readable like you said, but we can wait for @thymikee opinion.

Copy link
Member

Choose a reason for hiding this comment

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

I prefer {} as PropertyDescriptorMap. As long as TS is able to give me correct autocompletion, it's better to rely on inference and type less imho :)

@assuncaocharles
Copy link
Contributor

You may want to add // $FlowFixMe - converted to TS in the tools/config/index. It's the reason why the CI is not passing :)

@radko93
Copy link
Contributor Author

radko93 commented Sep 11, 2019

You may want to add // $FlowFixMe - converted to TS in the tools/config/index. It's the reason why the CI is not passing :)

@assuncaocharles missed that from other PRs, thanks

@thymikee thymikee merged commit b86313f into react-native-community:master Sep 11, 2019
@radko93 radko93 deleted the chore/assign-ts-migration branch September 11, 2019 10:41
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.

3 participants