Kyoto.js #1 㧠ãTypeScript è¨èªå¦çç³»ãã¨ã¯ããã ã¨ããçºè¡¨ããã¾ãã
2012 å¹´ 11 æ 15 æ¥ã«éå¬ããã Kyoto.js #1 㧠ãTypeScript è¨èªå¦çç³»ãã¨ã¯ããã ã¨ããçºè¡¨ããã¾ããã
çºè¡¨å 容
è³æ㯠SlideShare ã«ã¢ãããã¼ããã¾ããã
æ¦è¦
- åå㯠JavaScript ã«ä»£ããè¨èªã使ç¨ãããã¨ããåæ©ã®è©±ãããã㯠ãJavaScript æé«!!ã ã¨ãã話
- å¾å㯠TypeScript ã®è¨èªå¦çç³»ã (tsc ã³ãã³ãããã§ã¯ãªã) ç´æ¥ JavaScript ã§è§¦ã話
TypeScript ã®è¨èªã®åºæ¬çãªè©±ã¯ãã¦ãªãã§ã
TypeScript ã®è¨èªæ©è½ã ã¨ãæ§æã®è©±ã¯åºæ¬çã«ãã¦ã¾ããã ã¾ã JavaScript ã®åå¼·ä¼ã§ããã!
TypeScript ã®åºæ¬çãªãã¨ã¯å ¬å¼ãã¼ã¸ãã覧ãã ããã
ECMAScript ã£ã¦ä½ãªã®?
JavaScript ã®åå¼·ä¼ã«æ¥ããããªäººã¯ã¿ããªç¥ã£ã¦ããããããã¾ããããECMAScript ã£ã¦ã®ã¯ JavaScript ã®è¨èªæ©è½ã®ã³ã¢é¨åãæ¨æºåãã¦ä½ãããè¨èªã§ãã 詳細ã¯ä»¥ä¸ã®ãã¼ã¸ãè¦ãã¨ããã§ãããã
- ECMAScript è¨èªä»æ§ : Standard ECMA-262
- Mozilla Developer Center ã®ããã¥ã¡ã³ã : JavaScript の概要 - JavaScript | MDN (ãJavaScript 㨠ECMAScript ä»æ§ã ã®ç¯)
2012 å¹´ 11 æ 27 æ¥ç¾å¨ãECMAScript ã®ææ°ã®ãã¼ã¸ã§ã³ã¯ 5.1 ã§ãæè¿ã®ãã©ã¦ã¶ã¯åºæ¬çã« ECMAScript 5.1 ããµãã¼ããã¦ããã¨æãã¾ãã ECMAScript 5.1 ã«ã¯ã¯ã©ã¹å®ç¾©ã®æ§æãªã©ã¯ãªãã®ã§ãããç¾å¨çå®ä½æ¥ãé²ãã§ãã ECMAScript ã®æ¬¡ã®ãã¼ã¸ã§ã³ (ES.next ã¨ã ECMAScript 6 ã¨ãå¼ã°ãã¦ããã®) ã«ã¯ã¯ã©ã¹å®ç¾©ã®æ§æãªã©ãå«ã¾ããäºå®ã«ãªã£ã¦ãã¾ãã èæ¡ã¯å®æçã«å ¬éããã¦ãã¦ä¸è¨ãã¼ã¸ã§è¦ããã¨ãã§ãã¾ãã
TypeScript 㨠ECMAScript
TypeScript ã®æ§æ㯠ECMAScript 5 ã®æ§æã®ã¹ã¼ãã¼ã»ããã«ãªã£ã¦ãã¾ãã
TypeScript syntax is a superset of Ecmascript 5 (ES5) syntax.
TypeScript Language Specification 0.8 (PDF)
ã¤ã¾ããECMAScript 5 ã®æ§æã§æ¸ããã JavaScript ã®ã³ã¼ãã¯ãå ¨ã¦ TypeScript (0.8) ã®æ§æã¨ãã¦ãæ£ãããã¨ãããã¨ã ã¨æãã¾ã *1ã ã¾ããTypeScript ã®ã¯ã©ã¹å®ç¾©ã®æ§æãªã©ã¯ ECMAScript 6 ã®èæ¡ããã¼ã¹ã«ãã¦ããããã§ãã
ãããã£ãç¹ãèããã¨ããã§ã«åå¨ãã¦ãã JavaScript ã®ããã¸ã§ã¯ãããå°ãã㤠TypeScript ã«æ¸ãæãã¦ãããã¨ãããããªç§»è¡ã (ä»ã® JavaScript ãç½®ãæãããããªè¨èªã¨æ¯ã¹ã¦) ãããããã¨æãã¾ãã
TypeScript è¨èªå¦çç³»ã JavaScript ãã使ç¨ãã
TypeScript ã®ã³ã³ãã¤ã«ã®æ¹æ³ã¨ãã¦ãæãä¸è¬ç *2 ãªã®ã¯ tsc ã³ãã³ãã使ç¨ãã¦ãnode ä¸ã§ TypeScript è¨èªå¦çç³»ãåããã¦ã³ã³ãã¤ã«ããããã¨ã ã¨æãã¾ãã ãã ããã®æ¹æ³ã¯å®éã«ãã£ã¦ã¿ãã¨ã³ã³ãã¤ã«ãã¨ã«çµæ§æéãããã£ã¦ãã¾ãã¾ã (ç§ã®ç°å¢ã ã¨å°ã㪠TypeScript ãã¡ã¤ã«ã® 1 åã®ã³ã³ãã¤ã«ã« 3, 4 ç§ç¨åº¦ãããã¾ãã)ã ããã¯ãã³ã³ãã¤ã«ã®å¦çãã®ãã®ã«æéãããã£ã¦ããã®ã§ã¯ãªãã¦ãã³ã³ãã¤ã©ã®æºåã«ããããªã¼ãã¼ãããã大ãããã¨ãåå ã§ãããã
ããããåé¡ãåé¿ããããã«ãã³ã³ãã¤ã©ã®æºåãä¸åº¦ããããã®ããã»ã¹ããã£ã¨çãã¦ããã¦æ¯ååãããã»ã¹ã使ã£ã¦ã³ã³ãã¤ã«ããããã¨ãããããªãã¨ããããããã§ãããtsc ã³ãã³ãã使ã£ã¦ããã ãã§ã¯ãã¾ãç´°ããªå¶å¾¡ãã§ãã¾ãã *3ã ããã§ãTypeScript è¨èªå¦çç³»ã®å®ä½ã§ãã JavaScript ãç´æ¥è§¦ã£ã¦ã³ã³ãã¤ã«ããããã¦ã¿ã¾ããããã¨ãã話ã
TypeScript è¨èªå¦çç³»ã®å®ä½ã¯ãTypeScript ããã¸ã§ã¯ã ã®ä¸ã® bin/typescript.js ã¨ãããã¡ã¤ã«ã§ã *4ã ãããèªã¿è¾¼ã㨠TypeScript.TypeScriptCompiler
ã¨ããã³ã³ã¹ãã©ã¯ã¿ã使ããããã«ãªãã®ã§ã以ä¸ã®ãã㪠JavaScript ãæ¸ã㦠TypeScript ã®ã½ã¼ã¹ã³ã¼ããã³ã³ãã¤ã«ã§ãã¾ãã
// åºåç¨ãªãã¸ã§ã¯ãã®å®ç¾© var outfile = { source: "", Write: function (s) { this.source += s; }, WriteLine: function (s) { this.source += s + "\n"; }, Close: function () {} } // ã³ã³ãã¤ã©çæ var compiler = new TypeScript.TypeScriptCompiler(outfile); // ã¨ã©ã¼ã®æ±ã compiler.parser.errorRecovery = true; compiler.setErrorCallback(function (start, len, message, block) { console.log("error : " + message); }); // TypeScript ã®ã½ã¼ã¹ã³ã¼ã追å (ãããã³ã³ãã¤ã«ããã) var src1 = "class Test { aaa: string; };\n var ttt = 100;"; compiler.addUnit(src1, 'test1.ts'); var src2 = "///<reference path='test1.ts' />\nvar test = new Test(); test."; compiler.addUnit(src2, 'test2.ts'); // åãã§ã㯠compiler.typeCheck(); // å®è¡ // 以ä¸ã¯ TypeScript 0.8.0 ç¨ã«ç¬¬ 1 å¼æ°ã« bool å¤ã渡ãã¦ãã¾ãã // 0.8.1 ã§ã¯ä»¥ä¸ã® false ã¯æ¶ãå¿ è¦ãããã¾ã compiler.emit(false, function createFile(fileName) { console.log("create file : " + fileName); return outfile; }); console.log('compiled: ' + outfile.source); console.dir(compiler); // TypeScriptCompiler ãªãã¸ã§ã¯ãã®ä¸ãè¦ãã¨æ½è±¡æ§ææ¨ãè¦ãã
ã³ã¼ãè£å®ãããã
Vim ã Emacs 㧠TypeScript ãæ¸ããã¨ãèããã¨ãè¨è¿°ä¸ã® TypeScript ã®ã½ã¼ã¹ã³ã¼ãã®æå®ããä½ç½®ã«ãããèå¥åçã®ã³ã¼ãè£å®ããããããã®æ©è½ã欲ããã¨ããã§ãã ãã®ããã®æ©è½ã¯ TypeScript ã®ããã¸ã§ã¯ãã®ä¸ã«å«ã¾ãã¦ãã¾ãã
詳細ã¯ä»¥åè¨äºãæ¸ããã®ã§ãã¡ããåç §ãã ããã
ããããã°ä½ãã Microsoft ã®äººã TypeScript ã®ãµã¼ãã¹ç¨ããã¸ã§ã¯ãã¿ãããªã®ãå ¬éãã¦ã¾ããããããã¯ãªããªãã§ããããã ãTypeScript Services Serverã ã¨ããååããããã¨ãè£å®çã®è¨èªãµã¼ãã¹ãæä¾ãã¦ãããã®ãããããªãã§ããã (ã¡ããã¨è¦ã¦ãªãã®ã§ããããªãã)
Node 以å¤ã®ç°å¢ã§åãããã
TypeScript è¨èªå¦ç系㯠JavaScript ã§å®è£ ããã¦ãã¾ãããç¾å¨ (version 0.8.1) ã®ã¨ãããµãã¼ãããã¦ããã®ã¯ Windows ã® JScript å¦çç³» (?) 㨠Node ã ãã§ãã
ãã¾ãã¾ãª JavaScript è¨èªå¦ç系㧠TypeScript ã³ã³ãã¤ã©ãåããããã®é害ã¨ãã¦ããã¡ã¤ã«ã®èªã¿æ¸ããæ¨æºå
¥åºåçã® IO æ©è½ã JavaScript å¦çç³»éã§çµ±ä¸ããã¦ããªãã¨ããåé¡ãããã¾ãã TypeScript è¨èªå¦çç³»ã§ã¯ãIO
ã¨ãããªãã¸ã§ã¯ãã®ä¸ã« JavaScript è¨èªå¦çç³»åºæã® IO ã®æ©è½ãé ãºããããã¨ã§ãå®è£
éã®å·®ç°ãå¸åãã¦ãã¾ãã ãã®ãããåãããã JavaScript å¦çç³»ã«å¯¾å¿ãã IO ã®æ©è½ã IO
ãªãã¸ã§ã¯ãã®ä¸ã«è¨è¿°ããã°ããã® JavaScript å¦ç系㧠TypeScript å¦çç³»ãåãããã¨ãã§ããå¯è½æ§ãããã¾ãã
詳細ã¯ä»¥åæ¸ããè¨äºãã覧ãã ããã
ããã
JavaScript æé«!!
*1:ãã ããæ§æçã«ã¯æ£ããã¦ãã³ã³ãã¤ã«ã§ãããã©ããã¯å¥åé¡ã ä¾ãã°åãã§ãã¯ãéããªãã¦ã³ã³ãã¤ã«ã§ããªãå¯è½æ§ãããã
*2:VisualStudio ä¸ã§ä½¿ãå ´åãé¤ã
*3:tsc ã³ãã³ãã«ã¯ watch ãªãã·ã§ã³ã¨ãããã®ããã£ã¦ããã¡ã¤ã«ã®å¤æ´ãæ¤åºãã¦èªåçã«ã³ã³ãã¤ã«ãç´ããããã¦ãããã®ã§ããããã¾ãã¡ä½¿ãã«ããã
*4:TypeScript è¨èªå¦çç³»èªä½ã¯ TypeScript ã§æ¸ããã¦ãã¦ããããã³ã³ãã¤ã«ãããã®ããã® JavaScript ãã¡ã¤ã«ã§ãã