Last active
December 22, 2015 02:29
-
-
Save ichiroku11/6403881 to your computer and use it in GitHub Desktop.
Overload on Constants(定数によるオーバーロード)を試す Version:0.9.1.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.addEventListener("DOMContentLoaded", function(event) { | |
| var toString = Object.prototype.toString; | |
| // 文字列リテラルを使ってcreateElementを呼び出すと、HTMLAnchorElement | |
| // オーバーロードが有効になる | |
| var element1 = document.createElement("a"); | |
| // エラーにならない | |
| element1.href; | |
| console.log(toString.apply(element1)); // [object HTMLAnchorElement] | |
| // 変数を使ってcreateElementを呼び出すと、デフォルトのHTMLElement | |
| var tagName = "a"; | |
| var element2 = document.createElement(tagName); | |
| // error TS2094: The property 'href' does not exist on value of type 'HTMLElement'. | |
| //element2.href; | |
| console.log(toString.apply(element2)); // [object HTMLAnchorElement] | |
| // 関数の戻り値を使ってcreateElementを呼び出すと、デフォルトのHTMLElement | |
| var func = () => "a"; | |
| var element3 = document.createElement(func()); | |
| // error TS2094: The property 'href' does not exist on value of type 'HTMLElement'. | |
| //element3.href; | |
| console.log(toString.apply(element3)); // [object HTMLAnchorElement] | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working on TypeScript 0.9: Generics, Overload on Constants and Compiler Performance - TypeScript - Site Home - MSDN Blogsより。