"Inaccessible module" error when using typeof (TypeScript type specifier) - TS 0.9.1.1

Topics: General
Sep 13, 2013 at 5:43 AM
Edited Sep 13, 2013 at 6:13 AM
This issue is occurring in TypeScript 0.9.1.1. It took me a little while to track in my own code but I have stripped it down to a minimal reproduceable sample, as follows:

alpha.ts:
import beta = require('./beta');
export module alpha {
    export var g: typeof beta = beta;
}
beta.ts:
import gamma = require('./gamma');
export class beta {
    constructor(d: gamma.foo) {}
}
gamma.ts:
export class foo {}
The error is:
error TS2031: Exported variable 'g' is using inaccessible module 'gamma.ts'

I found a workaround, and that is to include a reference to gamma in alpha, but unless I'm misunderstanding something fundamental, this seems like something alpha should not have to worry about. A TypeScript bug?

Edit: The workaround mentioned works in the sample above, but I could not get the same to work in my own code, possibly due to more complex reference chains. Hopefully resolving this issue will resolve the issue in my own code. Until then, I've structured my code a different way.

Worth noting; the only reason for this code structure is because it's the only way I can think of to group components from different files into a single referenceable namespace. Would love to see something specifically designed to address this common requirement.
Sep 20, 2013 at 4:15 PM
"Worth noting; the only reason for this code structure is because it's the only way I can think of to group components from different files into a single referenceable namespace. Would love to see something specifically designed to address this common requirement."

+1 - I've encountered the same problem