-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor: Utilisation de TypeScript #51
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il reste quelques erreurs à corriger qui sortent avec la compilation TypeScript et TS Lint.
Pour sortir l'ensemble des erreurs de compilation tu peux installer TypeScript globalement avec yarn global add typescript
et ensuite rouler tsc
(ou tsc -w
pour avoir le watch). Quand je le roule dans le package React ça me dit qu'il reste 141 erreurs.
Même chose pour TS Lint, que tu peux installer globalement avec yarn global add tslint
et ensuite tu peux le rouler dans le package React avec tslint --project .
pour sortir les erreurs. Il y en a une trentaine présentement.
const [{ value }, setValue] = useState({ value: '' }); | ||
|
||
const handleChange = event => { | ||
const handleChange = (event: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event: ChangeEvent<HTMLInputElement>
(import { ChangeEvent} from 'react'
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Et c'était déjà de même, mais pas besoin de faire onChange={event => handleChange(event)}
dans l'Input. Tu pourrais faire directement handleChange={handleChange}
(même chose pour onKeyDown
)
@@ -98,7 +108,7 @@ const SearchInput = ({ disabled, hasButton, id, label, onChange, onSearch }) => | |||
} | |||
}; | |||
|
|||
const handleKeyDown = event => { | |||
const handleKeyDown = (event: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event: KeyboardEvent<HTMLInputElement>
(import { KeyboardEvent } from 'react'
)
disabled?: boolean; | ||
id: string; | ||
label: string; | ||
onBlur?: ((...args: any[]) => void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onBlur?(value: string): void;
id: string; | ||
label: string; | ||
onBlur?: ((...args: any[]) => void); | ||
onChange?: ((...args: any[]) => void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChange?(value: string): void;
label: string; | ||
onBlur?: ((...args: any[]) => void); | ||
onChange?: ((...args: any[]) => void); | ||
onFocus?: ((...args: any[]) => void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onFocus?(value: string): void;
minWidth?: number; | ||
} | ||
|
||
class MediaView extends Component<{}, {screenWidth: number, children?: Children}> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faire une interface pour le state et passer le type MediaViewProps
comme type de props. Et children dans le state n'est pas utilisé.
interface State {
screenWidth: number;
}
class MediaView extends Component<MediaViewProps, State> {
[...]
}
} | ||
|
||
class MediaView extends Component<{}, {screenWidth: number, children?: Children}> { | ||
constructor(props: any[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props: MediaViewProps
@@ -37,3 +45,5 @@ export default class MediaView extends Component { | |||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ligne 16 : Parenthèses inutiles, et espace de trop avant la virgule
Ligne 27 : Ça devrait être window.removeEventListener
plutôt que window.addEventListener
je pense.
componentDidMount, componentWillMount et handleScreeResize (typo) : devraient rien retourner. D'ailleurs le lint doit te dire de rajouter le type de retour : void
et : ReactFragment | null
pour la méthode render
Ligne 42 : children
peut être undefined. Je suis pas certain que React aime ça
value: number; | ||
} | ||
|
||
const getStep = ({ step, max, value }: GetStepProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L'interface n'est pas nécessaire je pense.
function getStep(step: number, max: number, value: number) : ReactElement {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
@@ -76,13 +83,13 @@ const getStep = (step, max, value) => { | |||
return <StepComponent key={step} />; | |||
}; | |||
|
|||
const Progress = ({ max, value }) => ( | |||
const Progress = ({ max, value }: {max: number, value: number}) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface pour les Props plutôt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
packages/react/package-lock.json
Outdated
@@ -0,0 +1,6112 @@ | |||
{ | |||
"name": "@equisoft/design-elements-react", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supprime ce fichier, il faut utiliser yarn
et non npm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
packages/react/package.json
Outdated
@@ -32,6 +33,7 @@ | |||
"url": "https://github.com/kronostechnologies/design-elements/issues" | |||
}, | |||
"dependencies": { | |||
"@types/lodash-es": "^4.17.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Devrait être dans les devDependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
import abstractStyle from './styles/abstract'; | ||
import { styles } from './styles/abstract'; | ||
|
||
export type Child = ReactNode | ReactNode[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supprime ce type, ReactNode
inclut déjà ReactNode[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
@@ -143,7 +153,7 @@ const SearchInput = ({ disabled, hasButton, id, label, onChange, onSearch }) => | |||
( | |||
<SearchSubmit | |||
disabled={disabled} | |||
type="submit" | |||
className="primary" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est voulu le className
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui, il y a une propriété className
sur le component searchButton
.
<StyledTextArea | ||
disabled={disabled} | ||
id={id} | ||
onBlur={(event: FocusEvent<HTMLTextAreaElement>) => {handleBlur(event); }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onBlur={handleBlur}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
disabled={disabled} | ||
id={id} | ||
onBlur={(event: FocusEvent<HTMLTextAreaElement>) => {handleBlur(event); }} | ||
onChange={(event: ChangeEvent<HTMLTextAreaElement>) => {handleChange(event); }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChange={handleChange}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
color?: string; | ||
} | ||
|
||
const Legend = ({ items }: any) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu devrais créér une interface pour les props :
interface Props {
items: Item[];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
<List> | ||
{items.map(item => ( | ||
{items.map((item: ItemProps) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En typant comme il faut les props et items
, tu n'aurais pas besoin de spécifier item: ItemProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
font-size: 0.875rem; | ||
`; | ||
|
||
const ProgressBar = ({ content }) => ( | ||
interface ElProps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ça veut dire quoi El
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EL
faisait référence à el
(element) dans le map:
<React.Fragment>
{content.map((el) => (
<div>
<Label secondary={el.secondary || false}>{el.descriptionLabel}</Label>
<Bar
color={el.color}
endLabel={el.endLabel}
percent={el.percent}
secondary={el.secondary || false}
/>
</div>
))}
</React.Fragment>
J'ai opté pour une solution similaire à ce que tu as suggéré pour legend.tsx
:
interface ProgressBarProps {
content: {color: string, descriptionLabel: string, endLabel: string, percent: string, secondary?: boolean}[];
}
const ProgressBar = ({ content }: ProgressBarProps) => (
Cela permet d'éliminer ElProps
.
secondary: boolean; | ||
} | ||
|
||
const ProgressBar = ({ content }: any) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fait une interface pour typer les props et content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
"paths": {} | ||
"paths": {}, | ||
"outDir": "./dist", | ||
"declaration": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faurait changer le plugin rollup pour https://github.com/ezolenko/rollup-plugin-typescript2
, celui utilisé (https://github.com/rollup/rollup-plugin-typescript
) supporte pas declaration: true
. Quand on fait yarn build
, ça ne fait que builder le bundle js dans dist/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merci pour l'info! J'ai fait la conversion.
a8bcc35
to
5ce285d
Compare
94048c8
to
2b72427
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gros refactor! 👍
Quelques modifications et questions. Les commentaires restants du review de Max M seraient aussi à corriger.
packages/react/package.json
Outdated
@@ -58,10 +59,11 @@ | |||
"eslint-plugin-import": "^2.16.0", | |||
"eslint-plugin-react": "^7.12.4", | |||
"husky": "^2.3.0", | |||
"lodash-es": "^4.17.14", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Devrait être dans dependencies
(à inverser avec @types/lodash-es
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
@@ -4,3 +4,4 @@ | |||
dist/ | |||
node_modules/ | |||
yarn-error.log | |||
.rpt2_cache/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce que c'est un dossier qui est créé automatiquement quand on génère les .d.ts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est le folder de cache généré par Rollup.
@@ -21,6 +21,8 @@ export default { | |||
exclude: 'node_modules/**', | |||
}), | |||
svgr({ icon: true }), | |||
typescript(), | |||
typescript({ | |||
objectHashIgnoreUnknownHack: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce que c'est parce qu'on avait cette erreur : ezolenko/rollup-plugin-typescript2#105 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui c'est exactement ça.
import abstractStyle from './styles/abstract'; | ||
import { styles } from './styles/abstract'; | ||
|
||
export type Child = ReactNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si on fait juste un équivalent syntaxique, on ne serait pas mieux de laisser ReactNode
et nous éviter de faire l'import de l'alias ailleurs dans l'application?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je suis d'accord, je vais changer ça.
@@ -1,16 +1,18 @@ | |||
import { ReactNode } from 'react'; | |||
import styled from 'styled-components'; | |||
|
|||
import abstractStyle from './styles/abstract'; | |||
import { styles } from './styles/abstract'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quand on importe le style de plusieurs fichiers différents ça crée des collision de noms de tous les nommes styles
. J'ai commencé à leur donné des noms spécifiques, on pourrait probablement faire la même chose ici (quelque chose comme { abstractStyle }
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
screenWidth: number; | ||
} | ||
|
||
class MediaView extends Component<MediaViewProps, State> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Devrait être refactored en Pure Function Component. Je crée une carte.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parfait!
@@ -6,7 +6,7 @@ const Container = styled.div ` | |||
display: flex; | |||
margin-bottom: 1rem; | |||
p { | |||
color: ${props => (props.secondary ? 'rgb(87, 102, 110)' : 'rgb(0, 0, 0)')}; | |||
color: ${(props: {secondary: boolean}) => (props.secondary ? 'rgb(87, 102, 110)' : 'rgb(0, 0, 0)')}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce qu'on est obligé de re-spécifier le type ici considérant que l'interface des props est déjà déclarée plus bas? On ne pourrais pas juste faire props: BarProps
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est un problème généré par l'utilisation de styled-components
avec TypeScript
. Si je met BarProps
comme sur la component, la styled-component
Container s'attend à recevoir toutes les components de BarProps
ce qui génère une erreur TypeScript
.
`; | ||
|
||
interface ProgressBarProps { | ||
content: {color: string, descriptionLabel: string, endLabel: string, percent: string, secondary?: boolean}[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que ça serait plus clean de créer une interface séparée pour le content et l'assigner ici.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonne idée! J'aurais pas pensé mettre une interface dans une interface.
@@ -2,14 +2,17 @@ | |||
"extends": "./node_modules/@equisoft/tslint-config/tsconfig.standards.json", | |||
"compilerOptions": { | |||
"target": "es6", | |||
"module": "commonjs", | |||
"module": "ESNext", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi est-ce qu'on fait cette modif?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nécessaire à Rollup
quand il est utilisé avec https://github.com/ezolenko/rollup-plugin-typescript2
.
@@ -1,5 +1,5 @@ | |||
import { configure } from '@storybook/react'; | |||
import '@equisoft/design-elements-web/style/body.css'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laisser le link vers le fichier CSS. Je pense qu'il manquerait juste à update la version de @equisoft/design-elements-web
dans le package.json de Storybook pour la dernière version (0.5.0) et le fichier CSS va être là.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai update la version et ça fonctionne. J'ai remis le fichier .css
dans config.js
.
J'ai intégré
DE-55
dans ce PR.