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

[Enhancement] improve typing #2501

Merged
merged 1 commit into from
Aug 13, 2024
Merged

Conversation

2wheeh
Copy link
Contributor

@2wheeh 2wheeh commented Jun 22, 2024

What are the changes?

It's minor type improvement.

Why am I doing these changes?

It's better for type safety.

What did change?

  • makes some implicit any to have proper types
  • removes some unnecessary assertions.

Screenshots/Videos

How to test the changes?

Checklist

  • There is no overlap with another PR?
  • The PR is self-contained and cannot be split into smaller PRs?
  • Have I provided a clear explanation of the changes?
  • Have I tested the changes (manually)?
    • Are all unit tests still passing? (npm run test)
  • [ ] Are the changes visual?
    • [ ] Have I provided screenshots/videos of the changes?

@CodeTappert CodeTappert added the Enhancement New feature or request label Jun 22, 2024
@@ -528,7 +528,7 @@ export abstract class PokemonSpeciesForm {
}
}

const pixelColors = [];
const pixelColors: integer[] = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typescript doesn't have an integer type can you use number instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found there are many integer in the codebase:

const total = pixelData.slice(i, i + 3).reduce((total: integer, value: integer) => total + value, 0);

which is type alias of number from phaser package.

// nodue_modules/phaser/types/phaser.d.ts
declare type integer = number;

So I thought it would be better for consistency if convention is to use integer over number when the value is integer case.

WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure for the phaser stuff we can keep it consistent and use integers

Comment on lines 1227 to 1230
for (let e = 0; e < evolutionChain.length; e++) {
// TODO: Might need to pass specific form index in simulated evolution chain
const speciesLevelMoves = getPokemonSpeciesForm(evolutionChain[e][0] as Species, this.formIndex).getLevelMoves();
const speciesLevelMoves = getPokemonSpeciesForm(evolutionChain[e][0], this.formIndex).getLevelMoves();
levelMoves.push(...speciesLevelMoves.filter(lm => (includeEvolutionMoves && !lm[0]) || ((!e || lm[0] > 1) && (e === evolutionChain.length - 1 || lm[0] <= evolutionChain[e + 1][1]))));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you destructure here so these loops are easier to read.

  1. const [ species, level ] = evolutionChain[e]
  2. speciesLevelMoves.filter(([ level, move ]) => { ... }

Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be worth doing inside of a separate PR instead of this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do in next PR !

Comment on lines 57 to 63
export type EvolutionLevel = [Species, integer];

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add jsdoc comments that explain what this type means. For example

/**
 * Pokemon evolution tuple type
 * @property 0 - Pokemon Species
 * @property 1 - The level at which it evolves
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added jsdoc in the way you suggest and changed it to a named tuple:

image

I wonder what is the best way to document tuple elements with jsdoc though. It doesn't seem well supported...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I tried looking it up but I couldn't find anything either. This is the best that I could come up with but if you find better by all means try it.

@2wheeh 2wheeh requested a review from OrangeRed June 26, 2024 04:12
@f-fsantos f-fsantos changed the base branch from main to beta July 10, 2024 17:47
@OrangeRed
Copy link
Collaborator

@2wheeh can you resolve the conflicts so this can be merged

@2wheeh
Copy link
Contributor Author

2wheeh commented Jul 17, 2024

@OrangeRed done ! sorry for the late iterate.

@torranx
Copy link
Collaborator

torranx commented Aug 7, 2024

@2wheeh please fix merge conflicts (again)

@2wheeh
Copy link
Contributor Author

2wheeh commented Aug 11, 2024

@torranx fixed.

Copy link
Contributor

@innerthunder innerthunder left a comment

Choose a reason for hiding this comment

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

🚀

@f-fsantos f-fsantos merged commit 452fbbb into pagefaultgames:beta Aug 13, 2024
4 checks passed
@2wheeh 2wheeh deleted the improve-type branch August 25, 2024 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants