fuhrmanator / FamixTypeScriptImporter

MIT License
2 stars 1 forks source link

How to handle "constructor signature" types? #43

Open fuhrmanator opened 1 year ago

fuhrmanator commented 1 year ago

Consider the following:

class Foo {}

const classType: typeof Foo = Foo; // classType is of type 'typeof Foo'
const someVar = Foo; // someVar is of type 'typeof Foo'
const instance = new classType(); // You can create an instance of Foo using classType

console.log(`classType: ${classType}`); // 
console.log(`someVar: ${someVar}`);
console.log(`classType === someVar: ${classType === someVar}`); // classType === someVar: true

console.log(`classType: ${classType}`); // classType: class Foo {}

console.log(`typeof Foo: ${typeof Foo}`); // typeof Foo: function
console.log(`typeof classType: ${typeof classType}`); // typeof classType: function

For now, ts-morph returns typeof Foo for the type of someVar -- that seems a strange Type in a Famix model. Perhaps Java has a similar thing? @nicolasanquetil