我沿着這些路線的打字稿應用的東西我建立什麼類型是構造函數?
class Thing {
static ReleventInfo: string
}
class Foo extends Thing { }
class Bar extends Thing { }
class Baz extends Thing { }
var things = {
foo: Foo,
bar: Bar,
baz: Baz,
}
function FooPlease(): Foo {
return new things.foo;
}
function ThingPlease(thing: string): Thing {
if (!things[thing])
return null;
var ctor = things[thing];
// ctor now has type of 'any', can't access 'ReventInfo' nicely.
var newThing = new ctor();
// newThing now has type of 'any'
return newThing;
}
其中工作,但打字稿(和智能)失去跟蹤什麼類型ctor
因此newthing
是,這是因爲有問題我希望訪問它們的靜態屬性和對象方法。 我應該說什麼類型的var
是?智能感知無助地提供這樣的信息:
整潔,我沒有意識到'typeof Thing'是一個實際的類型說明符。我認爲這是Intellisense試圖幫助。 (雖然想到它 - 顯然是) – 2014-11-06 10:57:53