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

Proposing Migration to TypeScript for Improved Development Experience #491

Open
2bfe26 opened this issue Apr 11, 2023 · 0 comments
Open
Labels
enhancement New feature or request issue:confirmed this is really a issue

Comments

@2bfe26
Copy link
Contributor

2bfe26 commented Apr 11, 2023

I would like to open a discussion regarding the migration of the project to TypeScript. As we continue to evolve and improve our codebase, I believe that adopting TypeScript will bring numerous benefits to our development process.

  • TypeScript eliminates the need for separate type definition files, which can be inconvenient and error-prone to manage.
  • Another benefit of migrating to TypeScript is that we can remove older libraries such as Babel and PropTypes, and rely solely on TypeScript for type checking and prop validation.
  • TypeScript allows us to configure various options, such as "implicit returns," which can make typescript almost equal to pure javascript

Here I refactor the Alert component to show how it will be like

import { useState, PropsWithChildren } from 'react';
import { Button } from '../Button';
import { Icon } from '../Icon';
import { Theme, theme as defaultTheme } from '../../theme';
import * as Styles from './Button.styles';

export type PropsAlert = PropsWithChildren<{
  icon?: string;
  onClose?: () => void;
  skin: 'primary' | 'success' | 'error' | 'neutral' | 'warning';
  theme: QuantumTheme;
}>

export function Alert(props: PropsAlert) {
  const { children, onClose, icon, skin = 'neutral', theme = defaultTheme, ...restProps } = props;

  const [show, setShow] = useState(true);

  if(!show) {
    return null;
  }

  return (
    <Styles.Wrapper theme={theme}>
      {icon ? <Styles.Icon name={icon} /> : null}
      {children ?? null}
      {onClose ?? (
        <Styles.ButtonClose
          theme={theme}
          onClick={() => {
            setShow(false);
            onClose();
          }}
        />
      )}
    </Styles.Wrapper>
  )
}

Some points of atention here:

  • Using a separate module for styles will help with readability
  • Props should be exported as well, it can be useful for other components
  • The default props should be done with the deconstruction of the props object
  • Named exports are preferable over default exports
    • index.ts modules can export everything from a other module with export * from "./other-module
    • Prevent name duplication
@2bfe26 2bfe26 added the enhancement New feature or request label Apr 11, 2023
@rapahaeru rapahaeru added issue:analyzing Someone is analysing this issue issue:confirmed this is really a issue and removed issue:analyzing Someone is analysing this issue labels Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request issue:confirmed this is really a issue
Projects
None yet
Development

No branches or pull requests

2 participants