Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise usage results in errors #293

Open
shkup opened this issue Jan 22, 2020 · 0 comments
Open

Promise usage results in errors #293

shkup opened this issue Jan 22, 2020 · 0 comments

Comments

@shkup
Copy link

shkup commented Jan 22, 2020

I use grunt with grunt-contrib-jshint on my bundle process for my asp.net core typescript files.
I have this super simple typescript code:

function delay(delay: number) {
    return new Promise(r => {
        setTimeout(r, delay);
    })
}

class Timer {
    constructor(public counter: number = 3, public delayMs: number = 1000) {
        this.doTimer();
    }

    async doTimer() {
        for (let i = 0; i < this.counter; i++) {
            await delay(this.delayMs);
            this.counter = this.counter - 1;
            console.log(this.counter);
        }
    }
}

The result js looks like this:

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
function delay(delay) {
    return new Promise(r => {
        setTimeout(r, delay);
    });
}
class Timer {
    constructor(counter = 3, delayMs = 1000) {
        this.counter = counter;
        this.delayMs = delayMs;
        this.doTimer();
    }
    doTimer() {
        return __awaiter(this, void 0, void 0, function* () {
            for (let i = 0; i < this.counter; i++) {
                yield delay(this.delayMs);
                this.counter = this.counter - 1;
                console.log(this.counter);
            }
        });
    }
}
//# sourceMappingURL=Timer.js.map

grunt-contrib-jshint is configured like that in my Gruntfile.js:

module.exports = function (grunt) {
    grunt.initConfig({
         concat: {
            all: {
                src: ['Script/Timer.js'],
                dest: 'temp/app.js'
            }
        },
        jshint: {
            files: ['temp/app.js'],
            options: {
                '-W069': false,
                'esversion': 6,
            }
        },
      }
    });

     grunt.loadNpmTasks('grunt-contrib-concat');
     grunt.loadNpmTasks('grunt-contrib-jshint');
};

grunt-contrib-jshint outputs the following errors:

temp/app.js
      3 |    return new (P || (P = Promise))(function (resolve, reject) {
                                           ^ Bad constructor.
      6 |        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
                                                                                                                           ^ Expected an 

I also tried to configure jshint with esversion 9. grunt-contrib-jshintis version 2.1.0.
What is wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant