Skip to content

Migration to typescript - #101

Closed
kamranayesh wants to merge 15 commits into
open-source-uom:mainfrom
kamranayesh:migration-to-typescript
Closed

kamranayesh wants to merge 15 commits into
open-source-uom:mainfrom
kamranayesh:migration-to-typescript

Conversation

@kamranayesh

@kamranayesh kamranayesh commented Apr 14, 2024 •

Copy link
Copy Markdown

Overview
This pull request introduces comprehensive TypeScript (TS) support by migrating the existing JavaScript (JS) codebase to TypeScript and transforming JSX files to TSX. This initiative enhances code quality, provides static typing, and improves maintainability and scalability of the project.

Changes Made

TypeScript Migration:

  • Refactored all JavaScript files (.js) to TypeScript (.ts).
  • Updated type definitions and added explicit typings where necessary.
  • Applied TypeScript strict mode to catch potential errors at compile-time.

JSX to TSX Conversion:

  • Converted all JSX files (.jsx) to TypeScript JSX (.tsx).
  • Ensured proper type annotations for React components and props.
  • Utilized TypeScript's JSX intrinsic elements for enhanced type checking.

Configuration Updates:

  • Updated project configurations (e.g., tsconfig.json) to enable TypeScript compiler options and enforce strict type checking rules.
  • Integrated TypeScript linting and ensured compliance with coding standards.

Next Steps

Testing and Validation:

  • Ensure comprehensive testing to validate the migration and resolve any potential issues.
  • Solicit feedback from the community and incorporate suggestions for further enhancements.

Continuous Improvement:

  • Continuously monitor TypeScript adoption metrics and address any lingering migration tasks.
  • Encourage adoption of TypeScript among contributors and provide necessary support and documentation.

This migration from JavaScript to TypeScript and JSX to TSX represents a significant milestone in enhancing the project's robustness, maintainability, and developer experience. The transition leverages TypeScript's advanced features to elevate the project's code quality and position it for sustainable growth and community engagement.

#gsoc_participant
Kamran Ayesh

@papsavas papsavas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this, it will REALLY help us moving forward. Couple of notes

Comment thread src/assets/data/map_data/auditoriums.ts Outdated
Comment thread src/assets/data/map_data/other.ts Outdated
const locations: Location[] = [
{
floor: i18n.t("mezzanine_floor"),
floor: String(i18n.t("mezzanine_floor")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing as as string. If the result is null, we would be assigning 'null' as String(null) -> 'null'
Resolve it with i18n.t(....) ?? undefined

Comment thread src/components/maps/MapCords.tsx Outdated
//this is needed to make sure it rerenders when the office selected in the floor changes
key={marked_position_x + " " + marked_position_y}
src={showGroundFloorImg ? GROUND_FLOOR_IMG_URL : imageURL}
src={showGroundFloorImg ? GROUND_FLOOR_IMG_URL : imageURL||""}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

its safer to imageURL ?? "". If imageURL returns null for some reason, the above will accept null. Funny js moment where if it was "" || null, "" would be accepted
image

Comment thread src/components/maps/MapCords.tsx Outdated
{showGroundFloorImg ? (
<Text pt={"0.125rem"} px="1rem">
{i18n.t("enter_elevator_prompt")} {floor.toLowerCase()}{" "}
{i18n.t("enter_elevator_prompt")} {floor&&floor.toLowerCase()}{" "}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can just floor?.toLowerCase() otherwise this might print false

key={index}
value={option.title}
onClick={() => handleMenuItemClick(option.title)}
onClick={() => handleMenuItemClick(option.title||"")}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since useMapData handles empty strings we're ok always calling the handler, but it would be wiser to use option.title ?? undefined if for some reason this becomes nullable

Comment thread src/components/professors/ProfList.tsx Outdated
<VStack>
{/* <input type="text" onChange={onTextChangeHandler} /> */}
<SecrCard data={secretary} key={secretary.tel} />
{secretary&&<SecrCard data={secretary} key={secretary?.tel||""} />}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Avoid this conditional rendering method.
Use

{secretary ? <SecrCard
 key={secretary.tel} //this is defined, no need for optional chaining (?.)
 data={secretary}
 /> : null}

Comment thread src/components/professors/ProfList.tsx Outdated
fontFamily="Syne"
type="text"
placeholder={i18n.t("searchProf")}
placeholder={i18n.t("searchProf")||""}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

?? undefined

Comment thread src/components/restaurant/MenuTable.tsx Outdated
>
<UnorderedList spacing={2}>
{Object.values(foodMenu[key]).map((dish, index) => (
{Object.values(foodMenu[key as FoodMenuKey]).map((dish, index) => (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not really important but you could raise typing to the outer (Object.keys(foodMenu) as Array<keyof FoodMenu>).map(...) having no need to cast later

@GeorgeFkd

Copy link
Copy Markdown
Contributor

Can you add further documentation regarding its deployment in docs/deployment.md? Is it still just npm run build and the rest still the same? Also should typescript's version be explicitly declared?(My JS ecosystem knowledge is limited) @papsavas can you provide your opinion in on this?

@papsavas

Copy link
Copy Markdown
Contributor

Also should typescript's version be explicitly declared?

it is declared on package.json but devs need to use the workspace version instead of their system installed. In VSCode you can change it in the bottom right

image
image

@GeorgeFkd

Copy link
Copy Markdown
Contributor

Thank you @papsavas, the README will soon have a section for the setup of the developer environment, @kamranayesh along with the other suggested changes make sure to include the documentation for the deployment as mentioned above and we will soon review to merge it and deploy it.

@kamranayesh

Copy link
Copy Markdown
Author

Thank you @papsavas for your comments i will resolve them all. I will surely add documentation and update readme as well.
Open for any other suggestions.
@GeorgeFkd @GeorgeApos @Tsalmas-Anastasios

@kamranayesh

Copy link
Copy Markdown
Author

@GeorgeFkd I have updated pr with resolved comments and added deployment instructions in readme.

@shivarm

shivarm commented Apr 19, 2024

Copy link
Copy Markdown
Contributor

@kamranayesh resolve the merge conflicts

@shivarm

shivarm commented Apr 19, 2024

Copy link
Copy Markdown
Contributor

@kamranayesh resolve the merge conflicts

and rebase or merge with main branch

@shivarm

shivarm commented Apr 28, 2024

Copy link
Copy Markdown
Contributor

@kamranayesh How is it working locally?

@kamranayesh

Copy link
Copy Markdown
Author

@shivam-sharma7 Its working fine. I request other contributors to checkout and test it too.

@shivarm shivarm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am seeing some error while reviewing this

  1. Setting page layout is looking weird

image

  1. when i have clicked http://localhost:3000/firstyearinfo the freshmen card then its show me the following errors

image

@GeorgeFkd @GeorgeApos @Tsalmas-Anastasios What do you think?

@GeorgeFkd

Copy link
Copy Markdown
Contributor

It seems to have to do with the markdown files being used there. The freshmen articles are just markdown files rendered into react components using a library. The imports there i remember were a bit weird. If you cant resolve it i will investigate it in a few days.

@papsavas

papsavas commented Apr 30, 2024 •

Copy link
Copy Markdown
Contributor

Are we planning to integrate vite here or in a future PR?
Right now, build script doesn't do much. If a type error is present, it doesn't catch it.

We should also avoid tsc, /dist and manual management of TS compiling in general.

vite react-ts template should be handy for this

@shivarm

shivarm commented May 1, 2024

Copy link
Copy Markdown
Contributor

@papsavas First of all we have to deal with markdown files then it would be next step because I am getting same error while migrating in vite

@GeorgeFkd

Copy link
Copy Markdown
Contributor

@papsavas I think we could do it on a next PR bcs this one is a huge chamge itself already. Also as @shivam-sharma7 mentioned we should investigate how to make markdown work in Vite.

@GeorgeApos GeorgeApos added enhancement New feature or request help wanted Extra attention is needed labels May 3, 2024
@GeorgeApos GeorgeApos added p.High Priority: High frontend This issue is related to frontend backend This issue is related to backend quality This issue is related to quality and removed backend This issue is related to backend labels May 3, 2024

@papsavas papsavas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the "implicit inference" review is not crucial right now. I would prioritize the missed as string one to speed up the merging process. Its a long PR already, we don't need to make it longer

let departmentLocations = {
import { Location } from "../../../../../hooks/useMapData";
import { DepartmentLocations } from "..";
const locations: Location[] = [...second_floor,...third_floor, ...fourth_floor];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you do not need to explicitly type this, its already infered as Location[] since all floors are. In general, prefer implicit inference. Code flows better that way

Comment thread src/assets/data/map_data/auditoriums.ts Outdated
Comment thread src/contexts/departmentContext.tsx Outdated
@GeorgeFkd

Copy link
Copy Markdown
Contributor

As there are some legacy peer dependencies it needs npm install --force to run.

This will be temporarily allowed in order to push through this PR.

@kamranayesh

Copy link
Copy Markdown
Author

As there are some legacy peer dependencies it needs npm install --force to run.

This will be temporarily allowed in order to push through this PR.

i updated package.json please try again

@naman9271

Copy link
Copy Markdown
Contributor

Hi @GeorgeFkd @GeorgeApos @papsavas I am interested in migration of this codebase to TS ... is this PR complete the migration or should i open mine for the migration of the codebase
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request frontend This issue is related to frontend help wanted Extra attention is needed p.High Priority: High quality This issue is related to quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants