æ©è½éçºãæ¢ããã«ã6ä¸è¡ã® TypeScript 移è¡ãå®äºãããéçºããã»ã¹
ã¹ã¿ãã£ã¹ã éçºé¨ æè¡æ¯æ´ã¦ãããã®ç¬¹æ¨ (@s_sasaki_0529) ã§ãã
2021å¹´ä¸åæãããã6ä¸è¡ã® JavaScript ã³ã¼ãã TypeScript ã«ç½®ãæããä½æ¥ããåå¹´éåç¬ã§è¡ãã¾ããã
æ¬è¨äºã§ã¯ãæ©è½éçºèªä½ãæ¢ããã«ãã©ã®ããã«èµ°ãåããã¨ãã§ããã®ãããµããããããã¨æãã¾ãã
ãªããæ¬è¨äºã®å 容ã¯ã移è¡éå§ç´å¾ã®ç»å£è³æ â大è¦æ¨¡ Vue ã¢ããªã±ã¼ã·ã§ã³ã® TypeScript 移è¡â ã¨ã移è¡å®äºå¾ã®ç»å£è³æ â6ä¸è¡ã® TypeScript 移è¡ã¨ãã®å¾â ã¨éè¤ããå 容ãå«ãã§ãã¾ãã
Teachme Biz 㨠TypeScript
å¼ç¤¾ãéçºãã¦ãããããã¥ã¢ã«ä½æã»å ±æã·ã¹ãã Teachme Biz ã¯ãiOS/Android ã Windows ãªã©ããã«ããã©ãããã©ã¼ã ã§æä¾ããã¦ãã¾ãã
ãã®ä¸ã§ããä½æã»ç®¡çã«å¤ã使ããã¦ãã Webãã©ã¦ã¶çã¯ã JavaScript 㨠Vue.js ã主ã¨ããã以ä¸ã®ãããªæè¡æ§æã¨ãªã£ã¦ãããæ´å²ççµç·¯ããã£ã¦ TypeScript ã¯ä½¿ç¨ãã¦ãã¾ããã§ããã
Webéçºã«ããã TypeScript ã®éè¦æ§ã¯èªãã¾ã§ãããã¾ãããå¼ç¤¾ã§ããåããªããã¨ã«ãã以ä¸ã®å大ãªã¹ã¯ãæ±ããä¸å ·åãçºçããããä¸ãéçºå¹çãä½ãç¶æ ãç¶ãã¦ãã¾ããã
- å±éº: Null ãå«ãã©ããªå¤ãå ¥ã£ã¦ãããæ¨æ¸¬ãã¥ãã
- ç¡ç§©åº: ã³ã¼ãã®èªç±åº¦ãé«ã¾ããä¸è²«æ§ã®ãªãã³ã¼ããéç£ããã
- éå¹ç: ã¨ãã£ã¿ã®æ¨è«ãæºè¶³ã«å¹ãããã¿ã¤ããèµ·ããããã
- æé»ç¥: è¨è¨ã«é¢ããæ å ±ãã³ã¼ãããå¾ã¥ãã
ä¸è¨ã®å大ãªã¹ã¯ã¯ãåã®åã§ä»¥ä¸ã®ããã«è§£æ±ºãããã¨ãã§ãã¾ãã
ããã¾ã§ã¯å大ãªã¹ã¯ãã ã¾ãã ã¾ãåãå ¥ãç¶ãã¦ãã¾ããããé·æçãªã¹ã±ã¼ã«ããVue 3 ã¸ã®ãã¤ã°ã¬ã¼ã·ã§ã³ãªã©ãè¦è¶ãã¨ã移è¡ã¯ä»ãããªãã¨ããå¤æã«è³ãã¾ããã
移è¡ç¯å²
移è¡ã決æããã¨ã¯ãããã©ãã¾ã§ãã©ã®ã¬ãã«ã§ç§»è¡ããã®ããäºã決ããå¿ è¦ãããã¾ãã
çµè«ããè¨ãã¨ã以ä¸ã®ãããªæ¹éã§ç§»è¡ãè¡ããã¨ã«ãã¾ããã
- .js ãã¡ã¤ã«ã¯(ä¸é¨ã®ä¾å¤ãé¤ãã¦) å ¨ã¦ç§»è¡ãã
- .vue ãã¡ã¤ã«ã¯ä¸å移è¡ããªã
- strict: true ã®ã«ã¼ã«ãè¨å®ãã
- plugin:@typescript-eslint/recommended ã使ç¨ãã
Vue ã対象å¤ã¨ããã®ã¯ãVue 3 ã¸ã®ãã¤ã°ã¬ã¼ã·ã§ã³ãèæ ®ããæãã©ã®ã¿ã¡ã³ã³ãã¼ãã³ãã®æ¸ãç´ããçºçããããåã®ä½¿ãæ¹ãå¤ãã£ããã¨äºåº¦æéã«ãªãããããã§ãã
.js ãã¡ã¤ã«ã«ã¤ãã¦ã¯ãåºæ¬çã«å ¨ã¦ã®ãã¡ã¤ã«ã対象ã¨ãã tsconfig ã eslint ã§ã®å³ããè¨å®ãä»ä¸ãã¾ããããã«ãã£ã¦ãimplicit any ã ts-ignore ã使ç¨ãããâ移è¡ã¯ãã¦ããå ¨ç¶åå®å ¨ãããªãâã¨ããå端ãªç¶æ ãæ¸ããã¾ãã (æ示ç㪠any èªä½ã¯ç¦æ¢ãããä»å¾ã®èª²é¡ã¨ãã)
éçºãã¼ã ã¨ã®èªèåãã
æ¢åã³ã¼ãã® TypeScript 移è¡ãé²ãã¦ããåéçºãã¼ã ãæ°è¦ã³ã¼ããå¾æ¥ã©ãã JavaScript ã§æ¸ãã¦ãã¾ãã¨ãã¢ãã¬ã¹ã¨äºã®ãããªç¶æ ã«ãªãã移è¡ããã¤ã¾ã§ãå®äºãã¾ããã
ããã§ãã¾ãã¯éçºãã¼ã å ¨ä½ã«ãæ¬è¨äºã§æ¸ããã¦ãããããªèæ¯ã¨ããã»ã¹ãå ±æããæ°è¦ã³ã¼ãã¯åºæ¬çã« TypeScript ã§æ¸ãã¦ãããã¤ã¤ãæ¢åã³ã¼ããæ¹ä¿®ããå ´åããå¯è½ãªéã TypeScript ã使ãããã«èªèãæãã¾ããã
ãã¡ããå¤ãã®ã¡ã³ãã¼ã¯ TypeScript æªçµé¨ã§ãããããç¸äºã¬ãã¥ã¼ãå¼·åããããå®è·µ TypeScript ã®è¼ªèªãè¡ããªã©ã社å ã¸ã® TypeScript ã®å¸æãå¿ããã¾ããã
移è¡ããã»ã¹
移è¡å¯¾è±¡ã .js ãã¡ã¤ã«ã®ã¿ã¨ã¯ãããã³ã¼ããã¼ã¹ä¸ã®JSãã¡ã¤ã«ã¯ããã¹ãã³ã¼ããå«ããã¨ç´¯è¨ã§6ä¸è¡åå¨ãããããè¨ç»çã«ç§»è¡ãé²ããå¿ è¦ãããã¾ãã
å åãªæéãããã¨ã¯ãããä»ã®éçºãã¼ã ã®æ¥åã¯æ¢ããããªãã¹ãéªéã«ãªããªãããã«ããããã«ã¯ã移è¡ãããã¡ã¤ã«ã¨æ©è½éçºã§ä¿®æ£ããããã¡ã¤ã«ã®è¡çªããæå°éã«çããå¿ è¦ãããã¾ãã
ãã®ããã移è¡ç¨ã®ä½æ¥ãã©ã³ããåãã¨ãããã¨ã¯ããããã¡ã¤ã«ã¾ãã¯ãã©ã«ãåä½ã§å°ãã移è¡ããåå¥ã« PR ãä½æãç´ æ©ããã¼ã¸(âãªãªã¼ã¹) ããã¨ãããµã¤ã¯ã«ãç¹°ãè¿ãã¾ããã
ãªããç´°ãã移è¡é åºã工夫ç¹ã¯ãUIT INSIDE ã§è©±ããã¦ãã LINE æ§ã®äºä¾ãåèã«ãã¦ãã¾ãã (ãã¤ã楽ããè´ãã¦ã¾ã!)
æ¤è¨¼ããã»ã¹
åè¿°ã®ããã«ãå°ãã移è¡ãã¦ãªãªã¼ã¹ã®ãµã¤ã¯ã«ãåãã¨ãããã¨ã¯ãããã ãæ¬çªç°å¢ã®ã³ã¼ããé »ç¹ã«æ¸ãæããã¨ãããã¨ã§ãã
éçºã®ãªã¹ã¯è»½æ¸ã®ããã® TypeScript 移è¡ã®ããã§ãæ°ãã«é害ãèµ·ããããã§ã¯æ¬æ«è»¢åãããã§ãã°ãåºãããã«ã¯ããã¾ããã
幸ãã«ã Teachme Biz ã®éçºç°å¢ã¯ã CI/CD ããã»ã¹ãå åã«æ´åããã¦ãã¾ãã
ã³ã¼ããããã·ã¥ãããã³ã«ã以ä¸ã®ãã¹ãã CircleCI ä¸ã§å®è¡ãããã®ã§ãåºæ¬çã«ã¯ CI ãéãã° OK ã¨å¤æã§ãã¾ãã
- åä½ãã¹ã(Jest)
- E2Eãã¹ã(Selenium)
- Visual Regression Testing (Storybook + reg-suit)
èªåãã¹ãããã¹ãã¦ãä¸å®ã®æ®ãæ¹ä¿®ãããå ´åãæ¤è¨¼ç°å¢ãç«ä¸ãã¦ãåå¥ã«æåæ¤è¨¼ãè¡ãã¾ãã
æ¤è¨¼ç°å¢ã«ã¤ãã¦ã¯ãå®è¡åºç¤ã kubernetes ã«ç§»è¡ãããã¨ããããç°¡åãªã³ãã³ãã§ãã¤ã³ã¹ã¿ã³ããªç¬ç«ããç°å¢ãç«ã¡ä¸ãããã¨ãã§ãã¾ããkubernetes ã«ã¤ãã¦ã¯ä»¥ä¸è¨äºã御覧ãã ããã
ããã¾ã§ãã¦ãªãä¸å®ãæ®ãå ´åãå¥é QA ã°ã«ã¼ãã«ç¸è«ãã¾ããéçºè èªèº«ã§ã¯è¦ã¤ããããªããæãã¤ããããªãä¸å ·åããç確ãªæ¤è¨¼ã§æ¢ãåºãã¦ãããã¾ãã
ãªãã¡ã¯ã¿ãªã³ã°
TypeScript 移è¡ã«é¢ãã¦ã¯ãå¤ãã®ããã°ãæ¸ç±ã§äºä¾ãç´¹ä»ããã¦ãã¾ããããªãã¡ã¯ã¿ãªã³ã°ãåæã«è¡ãã¹ããå¦ãã¨ããåé¡ãããä¸ããã¾ããå¤ãã®å ´åããªãã¡ã¯ã¿ãªã³ã°ã¯å¥æ èããã¹ãã¨ãè¨ããã¦ãã¾ãã
以ä¸ã®äºä¾ãå ·ä½çã«è¦ã¦ã¿ã¾ãããã
4ã¤ç®ã¯é説çãªãã§ãããããªãã¡ã¯ã¿ãªã³ã°ã¨TypeScript移è¡ãåæã«è¡ããªããã¨ãããã¨ã§ããTypeScript移è¡ã«é¢ãã¦ã¯ã対象ã¨ãªããã¡ã¤ã«ãã¢ããªå ¨ä½ã§é常ã«åºãã®ã§ããªãã¡ã¯ã¿ãªã³ã°ã¨TypeScript移è¡ãåæã«ãã£ã¦ãã¾ãã¨ããªã°ã¬ãã·ã§ã³ãã¹ããè½ã¡ãã¨ãã«ããã®åå ã移è¡æã«æå³ããæ··å ¥ãããã°ãªã®ããããã¨ããªãã¡ã¯ã¿ãªã³ã°ã®å½±é¿ãªã®ãåãåããé常ã«é£ãããªãã¾ãã
ã¾ããã¡ãã®ã»ãã大äºãªã®ã§ããããªãã¡ã¯ã¿ãªã³ã°ã¯å§ããã¨ããããªããªãã¾ããä»åå¤æ´ã¯ã¢ããªå ¨ä½ã«å½±é¿ããå¯è½æ§ãããã®ã§ããªãã¡ã¯ã¿ãªã³ã°ããå§ããã¨ããããããæ°ã«ãªã£ã¦ããã¤ã¾ã§ãã£ã¦ãTypeScript移è¡ãçµãããªãã¨ããç¶æ³ã«é¥ãã¾ãã
å ¨é¢çã«åæã§ããå¤ãã®å ´åã¯ãã®é¸æãæ£ããã¨æãã¾ãã
ãããå¼ç¤¾ã§ã¯ãéã«ãªãã¡ã¯ã¿ãªã³ã°ãã¤ã±ãã¨ããã¾ã§ãããªãã TypeScript 移è¡ãããã¨ããæ¹éã«ãã¾ããã主ãªçç±ã¯ä»¥ä¸ã®ã¨ããã§ãã
- åè¿°ã®æ¤è¨¼ããã»ã¹ãé常ã«å å®ãã¦ããã®ã§ããã°ã¬ãªã¹ã¯ãä½ã
- èªèº«ãå°ä»»ã§ TypeScript 移è¡ãè¡ã£ã¦ãããããæéãå åã«ãã
- æªæ¥ã¯äºæ³ã§ããªããããããã¨ã§ãªãã¡ã¯ã¿ãããã§æ¬å½ã«ãªãã¡ã¯ã¿ããã¨ã¯éããªã
- ãªãã¡ã¯ã¿ããã«ç¾è¡ã³ã¼ãã«åãä»ããã¨ãã«ãªã¹ãªåãåºæ¥ä¸ãã
å人çã«ã¯æå¾ã®ã大ããã§ããåã®ãªãä¸çã§ãå¢ãã§æ¸ãããã³ã¼ãã¯ããã¼ã¿æ§é ãç¡è¦ããã¡ã§ããã®å ¨ã¦ã«å¯¾å¿ããåãå®ç¾©ãããã¨ããã¨ãå¼ããããã¦ããããªåãåºæ¥ä¸ããã¾ããã¾ãããã®ã¿ã¤ãã³ã°ã§æ§æ©è½ã®ä¸è¦ã³ã¼ãããåç §ãããªããããã³ã¼ããæ´ãåºããã¨ã§ãä½è¨ãªåå®ç¾©ãæ¸ãããã¨ãã§ãã¾ãã
ãã®ãããããã¹ãåãå®ç¾©ããããããªãã³ã¼ããä¿®æ£ãããªãã¡ã¯ã¿ä½æ¥ãåæã«è¡ããã¨ã§ãã³ã¼ãå質èªä½ãé«ããã¨ããã®ãç®æãã¾ããã
é²æ管ç
å ¨ã¦ã® JS ãã¡ã¤ã«ã移è¡å¯¾è±¡ã«ããã¨ããã¤ã¤ãæ§ã ãªçµç·¯ã§ç§»è¡ä¸å¯è½ãªãã¡ã¤ã«ãå°ãªãããã¾ãããããã§ãåæã®éã« 70% ã®ç§»è¡ãå®äºãããã¨ãã OKR ãæ²ããããã TypeScript 移è¡å®äºã®ã´ã¼ã«ã¨å®ç¾©ãã¾ããã
é²æçã®ãã©ããã³ã°ã¯ãmasterãã©ã³ãã®åã³ãããæç¹ã§ã® TS ãã¡ã¤ã«ã¨ JS ãã¡ã¤ã«ã®ç·æ°(åã³è¡æ°) ã®æ¯çãè¨æ¸¬ããããã«ãã¾ããã
ä¸è¨ã¹ã¯ãªãããç¨ãã¦éè¨ãããã¼ã¹é åãè¦ãªãããåå¹´é移è¡ä½æ¥ãç¶ãããã¨ã§ã8ææ«ã«ã¡ããã©ç®æ¨ã«å°éãããã¨ãã§ãã¾ããã
ã¾ã¨ã
æ¬è¨äºã§ã¯ãJavaScript ã®ã³ã¼ã6ä¸è¡ããæ©è½éçºãæ¢ããã«ã1人㧠TypeScript ã«ç§»è¡ãããã¨ãã§ããè¦å ãæ´çãã¾ããã
å¼ç¤¾ã§ã¯ä»¥ä¸ã®ãããªæ¡ä»¶ãæã£ã¦ãããã¨ãããTypeScript 移è¡ããªãã¡ã¯ã¿ãªã³ã°è¾¼ã¿ã§å®ç¾ã§ããã¨è¨ãã¾ãã
- æè¡æ¯æ´ã¦ãããã¨ãããæ©è½éçºããç¬ç«ããé¨éãåå¨ãã
- å社ã®äºä¾ãäºåã«åæããé²ãæ¹ã決ãã¦ããçæãã
- æéã¨ç¯å²ã決ãããã©ããã³ã°ããªããéä¸å¯¾å¿ãã
- CI/CD ã«ãã£ã¦ãèªåãã¹ã/æåãã¹ãã®ããã®ä»çµã¿ãæã£ã¦ãã
æå¾ã«
ã¹ã¿ãã£ã¹ãã«ã¯ããããã£ãéçºåºç¤ã®æ´åã«å ¨åã注ããç°å¢ãç¨æããã¦ãã¾ããä»å¾ãããªãäºæ¥æ¡å¤§ãç®æãããã«ããããå¤ãã®ä»²éãæ±ãã¦ããã®ã§ããèå³ãããã¾ãããããã²ä¸ç·ã«åãã¾ãããï¼