0
型(型のインスタンスではなく)をパラメータとして渡したいと思っていますが、型を特定の基本型に拡張する必要がある規則を適用したいType型でインスタンスではなく型にチェックする
例
abstract class Shape {
}
class Circle extends Shape {
}
class Rectangle extends Shape {
}
class NotAShape {
}
class ShapeMangler {
public mangle(shape: Function): void {
var _shape = new shape();
// mangle the shape
}
}
var mangler = new ShapeMangler();
mangler.mangle(Circle); // should be allowed.
mangler.mangle(NotAShape); // should not be allowed.
基本的に私は私が何か...他にshape: Function
を交換する必要があると思いますか?
これはTypeScriptで可能ですか?
注:TypeScriptは、shape
にデフォルトのコンストラクタがあることも認識する必要があります。私はこのような何かをするだろうC#で...
class ShapeMangler
{
public void Mangle<T>() where T : new(), Shape
{
Shape shape = Activator.CreateInstance<T>();
// mangle the shape
}
}