ubershmekel
ubershmekel

Reputation: 12818

Exported variable has or is using private type TypeScript error

The following gets a rather cryptic TypeScript build error: Exported variable 'res' has or is using private type 'Result'.

interface Result {
    status: string;
    comment: string;
}

function runTest(st: any) {
    try {

    } catch (err) {
        console.log('Failed test task: ' + err);
        console.log('Failed test task: ' + st.name);
        console.log(err.stack);
        var res: Result = {
            status: 'bad',
            comment: 'Nodejs exception: ' + err,
        };
        //saveTestResult(st, res);
    }
};

export function what() {};

It's all ok if either:

What's going on here?

Upvotes: 2

Views: 3318

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221282

You've found a bug in the compiler. You can work around it by moving the declaration of res (this doesn't change the behavior of the code):

function runTest(st: any) {
    var res: Result;
    try {

    } catch (err) {
        console.log('Failed test task: ' + err);
        console.log('Failed test task: ' + st.name);
        console.log(err.stack);
        res = {
            status: 'bad',
            comment: 'Nodejs exception: ' + err,
        };
        //saveTestResult(st, res);
    }
};

Upvotes: 3

Related Questions