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

[#1936] Migrate c-summary-charts.vue to TypeScript #1976

Merged
merged 7 commits into from
Apr 11, 2023

Conversation

vvidday
Copy link
Contributor

@vvidday vvidday commented Apr 5, 2023

Part of #1936

Proposed commit message

Currently, despite the addition of TypeScript support, the frontend is
still largely written in JavaScript. This results in a lack of type
safety and many complex objects being passed around as unknown types,
which may in turn lead to errors.

Let's migrate one of the main components, c-summary-charts.vue, to
TypeScript. This will provide better type safety and reduce runtime
errors.

Other information

window.getAuthorDisplayName type definition

This PR changes the type for the authorRepos parameter in window.getAuthorDisplayName, from Repo[] to User[]. This was a mistake I made in the initial type definition (as both Repo and User have the displayName attribute).

@vvidday vvidday marked this pull request as ready for review April 5, 2023 10:23
@vvidday vvidday requested a review from a team April 5, 2023 10:24
Copy link
Contributor

@zhoukerrr zhoukerrr left a comment

Choose a reason for hiding this comment

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

@vvidday Just a minor point I want to point out. The rest LGTM!

frontend/src/components/c-summary-charts.vue Outdated Show resolved Hide resolved
@vvidday vvidday requested a review from zhoukerrr April 7, 2023 08:07
Copy link
Member

@ckcherry23 ckcherry23 left a comment

Choose a reason for hiding this comment

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

I have reviewed the code and overall, the TypeScript migration looks great!
However, I do have a comment about the prop types.

I noticed we are using generics to define the types under props in c-summary-charts as Array<string> for example, but in c-summary, we are making use of PropType so the equivalent here would be Array as PropType<string[]>.

Similarly, most of the attributes under data() are defined as [] as string[] but we could make use of generics here as well as [] as Array<string>.

Do you think we can standardize how we define our types using a lint rule?

frontend/src/components/c-summary-charts.vue Outdated Show resolved Hide resolved
Co-authored-by: Charisma Kausar <68203159+ckcherry23@users.noreply.github.com>
@vvidday
Copy link
Contributor Author

vvidday commented Apr 7, 2023

I have reviewed the code and overall, the TypeScript migration looks great! However, I do have a comment about the prop types.

I noticed we are using generics to define the types under props in c-summary-charts as Array<string> for example, but in c-summary, we are making use of PropType so the equivalent here would be Array as PropType<string[]>.

Similarly, most of the attributes under data() are defined as [] as string[] but we could make use of generics here as well as [] as Array<string>.

Do you think we can standardize how we define our types using a lint rule?

Great point about generics vs T[] syntax, according to TS docs they are equivalent, but I agree we should stick to one for consistency. Do you have a preference on which?

There does seem to be a lint rule for this, we can either choose generics or the T[] syyntax.

@zhoukerrr
Copy link
Contributor

@vvidday Personally I think the T[] syntax is cleaner and easier to write. But of course the team will have to come to an agreement. The lint rule and refactoring of the code code be done in a separate PR or be made as a good first issue for new developers to familiarise with our codebase.

@ckcherry23
Copy link
Member

ckcherry23 commented Apr 7, 2023

Great point about generics vs T[] syntax, according to TS docs they are equivalent, but I agree we should stick to one for consistency. Do you have a preference on which?

I think I would prefer the array-simple rule as it uses the more modern T[] syntax for simpler types while allowing Array<T | U> for more complex types (where (T | U)[] may be a confusing syntax). I will create a new issue for this, so that we can tackle it in another PR.

Copy link
Contributor

@zhoukerrr zhoukerrr left a comment

Choose a reason for hiding this comment

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

LGTM. Not sure how to work with the cypress warning regarding the unexpected console statement. I do think it is useful in some cases. Maybe a separate issue could be raise for this for new developers to work on?

@ckcherry23 ckcherry23 requested a review from a team April 7, 2023 09:33
@dcshzj dcshzj changed the title [#1936] Migrate c-summary-charts to TypeScript [#1936] Migrate c-summary-charts.vue to TypeScript Apr 11, 2023
@dcshzj dcshzj merged commit 95c0141 into reposense:master Apr 11, 2023
@github-actions
Copy link
Contributor

The following links are for previewing this pull request:

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.

6 participants