I'm struggling with explicitly assigning a type in TypeScript from a class nested within an object (essentially a namespace):
let obj = {
hello: class {
constructor: function () {
console.log('hi');
}
}
}
// Implicit type assignment in global space works
var inst = new obj.hello();
// However, explicitly assigning the type doesn't work.
var inst2: obj.hello;
function assign() {
inst2 = new obj.hello();
}
Click here to view on TS Playground. The output seems correct, but I'm confused as to why the typing information for inst2
defaults to any
.
Appreciate any insights!