çããèŠã€ããããã«å¿ èŠãªæåã®ãã®ãããªè³ªåã®1ã€ã¯ããéžæããèšèªã¯ã©ãã§ããïŒãã§ãã
è±å¯ãªéžæè¢ãšèšèªèŠä»¶ã«ã€ããŠ
å¥åŠãªããšã«ãããã³ããšã³ãã®èšèªã¯JavaScriptã§ããå¿ èŠã¯ãããŸããã§ããã æçµçã«ããã®ç®çã®ããã«ã©ã®èšèªãéžæãããŠããããã«èšè¿°ãããã³ãŒãã¯JavaScriptã§ã³ã³ãã€ã«ãããŸãã ãã ããã³ãŒããæ£ç¢ºã«ã³ã³ãã€ã«ããããã®ã¯ãéçºè ãäœæãããã®ãããããããéèŠã§ã¯ãããŸããã èšèªã®éžæã¯å®¹æã§ã¯ãããŸããã§ããã èæ ®ããªããã°ãªããªãããšã¯æ¬¡ã®ãšããã§ãã
- BuckleScript
- ClojureScript
- CoffeeScript
- ãã¬
- ElixirScript
- JavaScript 2016ããã³å°æ¥ã®èšèªããŒãžã§ã³
- JavaScript +ã¢ãããŒã·ã§ã³
- ãã
- ãã¥ã¢ã¹ã¯ãªãã
- çç±
- TypeScript
ãšããã§ãããã¯å®å šãªãªã¹ãããã¯ã»ã©é ãã åèšèªã«ã¯é·æãšçæããããŸãããã®ãããèšèªã®1ã€ãéžæã§ããããã«ã次ã®èŠä»¶ãçå®ããŸããã
- ããã¯åŒ·ãåä»ããããèšèªã§ãªããã°ãªããŸãã ã ã¿ã€ãã¯ããã¯ãã¬ãã«ã§ãããã¥ã¡ã³ãã®åœ¹å²ãæãããŸãã ãããã¯ãããçšåºŠãã³ãŒãã®æ£ç¢ºæ§ã確ä¿ããã®ã«åœ¹ç«ã¡ãããã«éèŠãªããšã«ã¯ããªãã¡ã¯ã¿ãªã³ã°ãç°¡çŽ åããŸãã 匷ãåä»ããããèšèªãæ¢ããŠãããã1ã€ã®èæ
®äºé
ã¯ãéçºé床ã§ãã äœæ¥ãé«éåããããã«ã匷ãåä»ããããèšèªãèŠã€ããããšããŸããã ãã®ãããªã¢ã€ãã¢ã¯ãå€ãã®ããã°ã©ããŒãéçºããå
žåçãªããžã§ã³ã«åãããã®ã§ãã ã€ãŸããããã¯éçºè
ã«ãšã£ãŠè¿œå ã®è² æ
ã§ãããäœæ¥ã®é床ãäœäžããããšäžè¬ã«åãå
¥ããããŠããŸãã ãã ããéçºé床ãäžããããšã¯ããšã©ãŒã®å¯èœæ§ãé«ããããšãæå³ããŸãã ã³ãŒãã¯ãããšãè¿
éã«èšè¿°ããããšããŠããã§ããã ãå°ãªããšã©ãŒãå«ãããã«å
¥åããå¿
èŠããããŸããã 匷åãªã¿ã€ãã³ã°ã¯ãæ¥æé·äžã®ãããžã§ã¯ãã§ã圹ç«ã¡ãŸãã åŒç€Ÿã®ãšã³ãžãã¢ããŒã ã¯åžžã«èŠæš¡ãæ¡å€§ããŠãããã³ãŒãã«æºãã人ã®æ°ã¯çå®ã«å¢å ããŠããŸãã
- åªãããµããŒãããŒã«ãå¿
èŠã§ãã ç§ãã¡ãããããšããŠããããšãèæ
®ããŠïŒãµã€ãã®å€§å¹
ãªåèšèšïŒãããªãã®æ°ã®è£å©ããŒã«ãç¬èªã«äœæããæéã¯ãããŸããã§ããã æ¢è£œã®ãªãŒãã³ãœãŒã¹ãœãªã¥ãŒã·ã§ã³ã䜿çšããŠè¿
éã«éå§ã§ããããšãéåžžã«éèŠã§ããã ããå
·äœçã«ã¯ããããã¯åé¡ã®ç¹å®ã®ããŒã«ã§ãã ããã¯ãäžè¬çãªãã«ãã·ã¹ãã ïŒWebpackãªã©ïŒãšã®çµ±åããªã³ã¿ãŒã®ãµããŒãããã¹ããã¬ãŒã ã¯ãŒã¯ãšã®ç°¡åãªçµ±åã§ãã äžéšã®èšèªã®è£å©ã·ã¹ãã ã®çµ±åãæããã§ãªãå Žåããã®èšèªã¯èæ
®ãããªããªããŸããã
- ãã®èšèªã¯æ·±å»ãªãããžã§ã¯ãã§äœ¿çšãããããšã«ãªã£ãŠããŸãã ã èšèªã¯è¯ãããã«èŠããããå®éã«ã¯åã
ã®æ奜家ã®å°ããªãããžã§ã¯ãã§ã®ã¿äœ¿çšãããŠããå Žåãããã¯ç§ãã¡ã®ä»äºã«ã¯äžé©åãããããŸããã ããã«ãèšèªãæ·±å»ãªãããžã§ã¯ãã§äœ¿çšãããŠããªãå Žåããã®ãããªèšèªãã©ã®ãããç¶ãããããã³èšèªéçºè
ããã®èšèªã§èŠã€ãã£ããšã©ãŒã«é¢ããã¡ãã»ãŒãžã«ã©ãã ãè¿
éã«å¿çãããã«ã€ããŠçåãçããŸãã
- éçºè
ã¯ãèšèªãååã«æ©ãç¿åŸããå¿
èŠããããŸã ã äžèšã®ãªã¹ãã«ã¯çŽ æŽãããèšèªããããŸãããå¯äžã®ãã€ãã¹ã¯ãéçºè
ãããããç¿åŸããã®ã«æéãããããããããšã§ãã ãã®äžã§ããç§ã¯ElmãšPureScriptã«ã€ããŠèšåããããšæããŸãã ãããã®äœ¿çšã®åé¡ã«ã€ããŠçå£ã«è°è«ããŸããã ããããæçµçã«ã¯ããããã®å®è£
ã¯ããããã«ç²ŸéããŠããªãéçºè
ãããââãžã§ã¯ãã§çç£çã«äœæ¥ã§ããã¬ãã«ã«éããã«ã¯ããããã«æ
£ããŠããªãéçºè
ã«ããæ°ããããã°ã©ãã³ã°æŠå¿µã®éçºã«å¿
èŠãªäœæ¥ãå€ãããããšãæå³ããããšãå€æããŸããã
- èšèªã¯ãã¯ã©ã€ã¢ã³ããšãµãŒããŒã®äž¡æ¹ã§åäœããã¯ãã§ãã Redditã§ã¯ãSEOã¯éåžžã«éèŠã§ããããããã©ãŠã¶ã§è¡šç€ºã§ããããŒãžãé
ä¿¡ããããã®ãŠãããŒãµã«ã·ã¹ãã ã®æ¬ åŠã¯å€§ããªåé¡ã§ãã
- åªããã©ã€ãã©ãªãµããŒã ã ãã¹ãŠããŒãããæžãã€ããã¯ãããŸããã§ããã ä¿¡é Œã§ãããå®çžŸã®ããã©ã€ãã©ãªãå¿ èŠãšããã¿ã¹ã¯ãããã€ããããŸãã ç§ãã¡ã¯ãæ¢åã®ã©ã€ãã©ãªããå¿ èŠãªãã®ãéžæããæ©äŒãåŸãããšèããŸããã
ãããã®èŠä»¶ãæ€èšããåŸã2ã€ã®ãªãã·ã§ã³ã決å®ããŸããã 1ã€ç®ã¯TypeScriptã§ãã 2çªç®ã¯JavaScript + Flowã§ãã ããããæçµçãªéžæãè¡ãåã«ãTypeScriptãšFlowã®æ©èœãããã³ãããã®éããã§ããã ãããç解ããå¿ èŠããããŸããã
ç·šéãŸãã¯æ³šéïŒ
TypeScriptãšFlowã®éèŠãªéãã®1ã€ã¯ãTypeScriptã¯JavaScriptã«ã³ã³ãã€ã«ãããèšèªã§ãããFlowã¯JavaScriptã³ãŒãã«è¿œå ã§ããå泚éã®ã³ã¬ã¯ã·ã§ã³ã§ããããšã§ãã 泚éä»ãã³ãŒãã®æ£ç¢ºæ§ã¯ãéçã¢ãã©ã€ã¶ãŒã«ãã£ãŠãã§ãã¯ãããŸãã
äžèšã®éãã¯ãããã°ã©ã ã®äœææ¹æ³ã«çŽæ¥åœ±é¿ããŸãã ããšãã°ãTypeScriptããã³Flowã®åæã§ã®äœæ¥ãèŠãŠãã ããã
TypeScript
enum VoteDirection { upvoted = 1, notvoted = 0, downvoted = -1, }; const voteState: VoteDirection = VoteDirection.upvoted;
æµã
const voteDirections = { upvoted: 1, notvoted: 0, downvoted: -1, }; type VoteDirection = $Keys<typeof voteDirections>; const voteState: VoteDirection = voteDirections.upvoted;
TypeScriptã¯ã³ã³ãã€ã«ãããèšèªã§ãããããå®è¡æã«å®çŸ©ãããåãäœæããããã«äœ¿çšã§ããŸãã ãããŒã§ã¯ãåã¯åãªã泚éã§ãããããã³ãŒãå€æã«äŸåããŠå®è¡æã«åè¡šçŸãäœæããããšã¯ã§ããŸããã
ãã ããTypeScriptã¯ã³ã³ãã€ã«ãããèšèªã§ãããšããäºå®ã«ãããããã€ãã®æ¬ ç¹ããããŸãã TypeScriptãæ¢åã®ã³ãŒãããŒã¹ã«çµ±åããå Žåãã³ã³ãã€ã©ããã«ãããã»ã¹ãè€éã«ããå¯èœæ§ããããŸãã Babelãšãã©ã³ã¹ãã€ã¬ãŒã·ã§ã³ã¬ã€ã€ãŒã䜿çšãããã«ãããã»ã¹ã確ç«ãããŠããŸãã TypeScriptã«åãæ¿ããŠãç¶æãããæé©åãããã€ããããããæ¢åã®äœæ¥ã¹ããŒã ãç Žå£ããªãTypeScriptãçµ±åããæ¹æ³ãå¿ èŠã§ããã TypeScriptã¯ãã¯ããã«è€éãªãã«ãããã»ã¹ããããããŸãã
TypeScriptåŠçãšã¯å¯Ÿç §çã«ãBabelã¯Flowã¿ã€ãã®æ³šéãèªåçã«åé€ããŸãã Flowãéžæããå Žåãã¢ããªã±ãŒã·ã§ã³ã®æ§ç¯ããã»ã¹ã¯è€éã§ã¯ãããŸããã
ã³ãŒãæ€èšŒ
ã³ãŒãæ€èšŒã®åéã§ã¯ãéåžžãFlowã¯TypeScriptãããããã©ãŒãã³ã¹ãé«ããªããŸãã Flowã§ã¯ãããã©ã«ãã§ã
NULL
åã䜿çšããããšã¯çŠæ¢ãããŠããŸãã TypeScript 2.xã§ã¯ã
NULL
èš±å¯ãããŠããªãåã®ãµããŒããè¿œå ãããŸãããããã®æ©èœãèªåã§æå¹ã«ããå¿ èŠããããŸãã ããã«ãFlowã¯åãããé©åã«è¡šç€ºããŸãããTypeScriptã¯ãã°ãã°
any
åç §ã
any
ã
NULL
ãšåæšè«ãèš±å¯ããåã«å ããŠãFlowã¯å ±åæ£ãšååæ£ã®åé¡ã«é©ããŠããŸãïŒãã®ãããã¯ã«é¢ããè³æã¯ãã¡ãã§ã ïŒã ããã§ã®å žåçãªåé¡ç¶æ³ã®1ã€ã¯ãåä»ãé åã®æäœã§ãã ããã©ã«ãã§ã¯ãFlowã®é åã¯äžå€ã§ãã ããã¯ãFlowã®æ¬¡ã®æ§æããšã©ãŒãã¹ããŒããããšãæå³ããŸãã
æµã
class Animal {} class Bird extends Animal {} const foo: Array<Bird> = []; foo.push(new Animal()); /* foo.push(new A); ^ A. This type is incompatible with const foo: Array<B> = []; ^ B */
ãã ããTypeScriptã§åãããšãããããšãããšããšã©ãŒã¡ãã»ãŒãžãªãã§å€±æããŸãã
ã¿ã€ãã¹ã¯ãªãã
class Animal {} class Bird extends Animal {} const foo: Array<Bird> = []; foo.push(new Animal()); // typescript
ããã«å€ãã®é¡äŒŒããäŸãèŠã€ããããšãã§ããŸãããäžè¬çãªçµè«ã¯ããããŒã¯TypeScriptãããåãã§ãã¯ã§ã¯ããã«åªããŠããããšã§ãã
çæ ç³»
ãããŸã§è¿°ã¹ãŠããããšã¯ãã¹ãŠãFlowã®å©ç¹ã«ã€ããŠèªã£ãŠããŸãã ãããžã§ã¯ãã«çµ±åããæ¹ãç°¡åã§ãåãã§ãã¯ã«ããŸã察å¿ããŸãã ãªãTypeScriptã§åæ¢ããã®ã§ããïŒ
TypeScriptã®æãéèŠãªå©ç¹ã®1ã€ã¯ããã®ãšã³ã·ã¹ãã ã§ãã ããã¯çŽ æŽãããã©ã€ãã©ãªããµããŒãããŠããŸãã 䜿çšããã»ãšãã©ãã¹ãŠã®ã©ã€ãã©ãªãŒã¯ãã©ã€ãã©ãªãŒèªäœã«ã¿ã€ãã®èª¬æããããã DefinitelyTypedã§æ瀺ãããŠããŸãã ããã«ãTypeScriptã¯ãVSCodeããã³äœ¿çšããŠããä»ã®äžè¬çãªãšãã£ã¿ãŒã®ãã©ã°ã€ã³ïŒAtomãSublimeTextãªã©ïŒã§åªããIntelliSenseããµããŒãããŠããŸãã ããã«ãTypeScriptãJSDocã¢ãããŒã·ã§ã³ãåŠçã§ããããšãçºèŠããŸããã JavaScriptã䜿çšããŠTypeScriptã«åãæ¿ãããããããã¯ç¹ã«æçšã§ããããšãå€æããŸããã
ããã«ãTypeScriptã¯ããã瀟äŒçéèŠæ§ããé«ãã圌ã®äººçã¯ååã«é·ããªããšããæèŠããããŸãã TypeScriptã䜿çšããããã€ãã®å€§èŠæš¡ãªãããžã§ã¯ãïŒVSCodeãRxjsãAngularãTypeScriptèªäœïŒãããããããã®æ©èœã»ããããããžã§ã¯ãã®ç®æšãéæããä»åŸæ°å¹Žéã§ãã®èšèªã䜿çšã§ãããšç¢ºä¿¡ããŠããŸããã©ãã«ãè¡ããªãã Flowã«ã€ããŠã¯ãFacebookäžã®ç¹å®ã®ã¿ã¹ã¯ã解決ããããã«äœæããããã®ã§ããããã®éçºã¯åãç¯å²ã®ã¿ã¹ã¯ã«ãã£ãŠæ±ºå®ãããããšãå¿é ããŠããŸãã äžæ¹ãTypeScriptã¯å¹ åºãåé¡ã«çŠç¹ãåœãŠãŠãããMicrosoftã¯çŸåšåãçµãã§ããŸãã ããã«ããããšã©ãŒãçºçããŠããããå ±åããå Žåã圌ãã¯ç§ãã¡ã®å£°ãèããŠè¡åãèµ·ãããšæ³å®ã§ããŸãã
ããã«ãTypeScriptã¯JavaScriptã®ã¹ãŒããŒã»ããã§ãããããTypeScriptã®éçºãç¹ã«æ°ããåãšèšèªæ§æäœã®ãµããŒãã¯ãJSã®éçºã«ç¶ãããšãæåŸ ã§ããŸãã èšèªãšåã®ã·ã¹ãã ã¯äžŠè¡ããŠéçºãããŸãããããã®äœæ¥ãé²è¡äžã ããã§ãã
ãŸãšã
TypeScriptãéžãã ã®ã¯ãæ°ããéçºè ãå¿ èŠãšãããã¹ãŠã®ãã®ããã°ããæããããšãã§ãããšç¢ºä¿¡ããŠããããã§ãïŒæšå¹Žãããã³ããšã³ããšã³ãžãã¢ã®æ°ã¯3åã«ãªããŸããïŒã ãã®èšèªã¯ããµã€ãã®åèšèšã«ãããããŒãºãæºãããŠãããšç¢ºä¿¡ããŠããŸãã ããã«ããã¹ãŠãTypeScriptãé·æéååšããããšã瀺åããŠãããç§ãã¡ã®èª¿æ»ã§ã¯ãTypeScriptãã³ãŒãããŒã¹ãšããŸãçµ±åãããããšã瀺ãããŠããŸãã ããããç§ãã¡ã«ãšã£ãŠæãéèŠãªããšã¯ã匷ãåä»ããããèšèªãžã®ç§»è¡ã§ãã
åä»ãèšèªã䜿çšãããšããã§ã«ããã€ãã®çµæãåŸãããŠããŸãã ã³ãŒãã«å«ãŸããåé¢é£ã®ãšã©ãŒã¯å°ãªãã倧èŠæš¡ãªãªãã¡ã¯ã¿ãªã³ã°ãããèªä¿¡ãæã£ãŠå®è¡ããŸãã åã蟌ã¿ããã¥ã¡ã³ãã¯ããªããžã§ã¯ããšé¢æ°ãã©ã¡ãŒã¿ãŒã®å éšæ§é ãèšè¿°ããã®ã§ã¯ãªããæŠå¿µã«çŠç¹ãåãããŠããŸãã ãã®çµæãTypeScriptã¯ãŸãã«ç§ãã¡ãå¿ èŠãšããŠãããã®ã§ãããšèšããŸãã
芪æãªãèªè ïŒ TypeScriptãŸãã¯Flowã䜿çšããŠããŸããïŒ