Open
Description
Currently, there is special code in the checker to look up values as type in order to support the value-only way that the binder exports things that come from an export assignment, even things that in Typescript export types, such as classes.
The binder should instead treat JS export assignments as types if the initialiser (such as a class or constructor function) or later assignments (such as prototype assignments) warrant it. That means the checker code will be more uniform and easier to understand.
Code
function F() {
}
F.prototype.method = function() {
}
exports.F = F
Allows F
to be used as a type:
var x = require('./module')
/** @type {x.F} */
But this doesn't work in pure typespace:
/** @typedef {import('./module').F} F */
/** @type {F} */
var f;
Note that binding this way will enable tricks that aren't possible in Typescript today:
module.exports. C = class {
}
module.exports.C.D = class {
}
Now var m = require('./module')
makes both m.C
and m.C.D
available as types.