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(types): add type information #791

Merged
merged 1 commit into from Mar 20, 2019
Merged

Conversation

sendilkumarn
Copy link
Member

What kind of change does this PR introduce?

Adds some type related information and removed where it is obvious

Did you add tests for your changes?
N/A
If relevant, did you update the documentation?
N/A
Summary
leverage on type inference

r? @evenstensberg @ematipico @dhruvdutt

Does this PR introduce a breaking change?

Other information

Copy link
Contributor

@misterdev misterdev left a comment

Choose a reason for hiding this comment

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

Just my 2 cents on this :)

Seems reasonable to me to remove the type when:

  • the name of the variable is clear: packageJSONPath
  • the type of the assigned value is clear: let hasProp = false;
  • we use a common function: const filePaths = args.slice(3);

I would keep the type when:

  • we use a custom function: const transformations = mapOptionsToTransform(config);
  • we initialize a variable using another variable: const temp = action;

@@ -73,7 +72,7 @@ const traverseAndGetProperties = (arr: object[], prop: string): boolean => {
const searchProps = (answers: object, input: string): Promise<string[]> => {
input = input || "";
return Promise.resolve(
PROPS.filter((prop: string): boolean =>
PROPS.filter((prop): boolean =>
Copy link
Contributor

Choose a reason for hiding this comment

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

In other occurrences of .filter you are keeping the type of the parameter. I would keep here too

Copy link
Member Author

Choose a reason for hiding this comment

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

You are correct here. we need to have it here.

@@ -162,7 +161,7 @@ export default class AddGenerator extends Generator {
this.configuration.config.item = action;
});
}
const temp: string = action;
const temp = action;
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look obvious to me. I would keep the type here

Copy link
Contributor

Choose a reason for hiding this comment

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

action is already a string, so temp inherits its type


webpackConfig.forEach((scaffoldPiece: string): Promise<void> => {
const config: IConfiguration = webpackProperties[scaffoldPiece];
const transformations: string[] = mapOptionsToTransform(config);
const transformations = mapOptionsToTransform(config);
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look obvious to me what's the return type of mapOptionsToTransform

Copy link
Member Author

Choose a reason for hiding this comment

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

My inspiration for this and the above one is from the Typescript core repo. Again here the type is obvious if you know the method signature or the variable and we don't need to be verbose.

But well, I agree it is highly subjective...

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually there's no need to assign a type if the function already has a signature (and just one, where it returns always a string).

@ghost
Copy link

ghost commented Mar 16, 2019

There were the following issues with this Pull Request

  • Commit: dd03674
    • ✖ message may not be empty
    • ✖ type may not be empty

You may need to change the commit messages to comply with the repository contributing guidelines.


🤖 This comment was generated by commitlint[bot]. Please report issues here.

Happy coding!

@webpack-bot
Copy link

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@@ -230,7 +237,7 @@ function addOrUpdateConfigObject(

if (propertyExists) {
rootNode.properties
.filter((path: INode) => path.key.name === configProperty)
.filter((path: INode): boolean => path.key.name === configProperty)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it needed the type here?

Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

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

lgtm, leaving @ematipico up for final call

@evenstensberg
Copy link
Member

Needs a quick rebase @sendilkumarn

chore(types): fix lint issue

chore(types): add missing types
@webpack-bot
Copy link

@sendilkumarn Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@evenstensberg Please review the new changes.

@sendilkumarn
Copy link
Member Author

Done rebasing, let us merge this once the builds are green 🎉

@ematipico ematipico merged commit 473ff4a into webpack:master Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants