Botframework-sdk: compiler error TS2399: duplicate identifier "_this" at line 442 of bots/UniversalBot.ts

Created on 26 Nov 2016  路  5Comments  路  Source: microsoft/botframework-sdk

Hi.
complete error message was...
bots/UniversalBot.ts(442,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference.

I'm new to tsc. While trying to resolve the issue I came across following link...
http://stackoverflow.com/questions/12710303/should-creating-a-variable-named-this-conflict-with-this

Most helpful comment

Prefixing _this with an extra underscore resolved my issue. Code got compiled and used in a bot.

private eventMiddleware(event: IEvent, middleware: IEventMiddleware[], done: Function, error?: (err: Error) => void): void {
        var i = -1;
        var __this = this;
        function next() {
            if (++i < middleware.length) {
                __this.tryCatch(() => {
                    middleware[i](event, next);
                }, () => next());
            } else {
                __this.tryCatch(() => done(), error);
            }
        }
        next();
    }

Removing/commenting line var _this = this; may work as well.

All 5 comments

What version of the TypeScript compiler are you using?

version 2.2.0

Prefixing _this with an extra underscore resolved my issue. Code got compiled and used in a bot.

private eventMiddleware(event: IEvent, middleware: IEventMiddleware[], done: Function, error?: (err: Error) => void): void {
        var i = -1;
        var __this = this;
        function next() {
            if (++i < middleware.length) {
                __this.tryCatch(() => {
                    middleware[i](event, next);
                }, () => next());
            } else {
                __this.tryCatch(() => done(), error);
            }
        }
        next();
    }

Removing/commenting line var _this = this; may work as well.

@sohail seems like the latest stable version is 2.0.10, any particular reason you are using 2.2.0? Here is the list of 2.2.0 versions I see: 2.2.0-dev.20161128, 2.2.0-dev.20161127, 2.2.0-dev.20161126, 2.2.0-dev.20161125, 2.2.0-dev.20161124, 2.2.0-dev.20161123, 2.2.0-dev.20161122, 2.2.0-dev.20161121, 2.2.0-dev.20161120, 2.2.0-dev.20161118, 2.2.0-dev.20161117, 2.2.0-dev.20161116, 2.2.0-dev.20161115, 2.2.0-dev.20161114, 2.2.0-dev.20161113, 2.2.0-dev.20161112, 2.2.0-dev.20161111 they are all marked dev (not ready for production). I would recommend using latest stable version.

No, no particular reason, I just cloned the repository, compiled TS compiler and used that to compile botbuilder SDK.
After that small change of code, things are working as they should and my BOT is happy.

Was this page helpful?
0 / 5 - 0 ratings