Skip to content

Instantly share code, notes, and snippets.

@pointwiseproduct
Last active July 28, 2016 15:50
Show Gist options
  • Save pointwiseproduct/68cf8e9b3610686dc827536e1140ea7c to your computer and use it in GitHub Desktop.
Save pointwiseproduct/68cf8e9b3610686dc827536e1140ea7c to your computer and use it in GitHub Desktop.
// TypeScriptのめんどくさいところ.
class A{
value: number;
// 引数の型が違うコンストラクタを分けて記述できない.
// constructor(){ ... }
// constructor(other: A){ ... }
// 仕方が兄のでvalue?: anyを列挙してコンストラク内部でinstanceofチェックをする.
constructor(_other?: any){
// default constructor.
if(_other == null){
this.value = 114514;
return;
}
// copy constructor.
if(_other instanceof A){
let other: A = <A>_other; //_otherはAって分かりきってるのに一々キャするの!?
this.value = other.value;
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment