Typescript-eslint: Regression: @typescript/require-await causes "Cannot set property 'hasAwait' of null"

Created on 20 Nov 2019  路  3Comments  路  Source: typescript-eslint/typescript-eslint

I set

        'require-await': 'off',
        '@typescript-eslint/require-await': 'error',

and alsoturning off the typescript-eslint rule gets rid of the error.

I'm getting this error only since today after "yarn upgrade" upgrade typescript-eslint (it worked with the previous published version, I run that package upgrade command daily).

So this seems to be a regression.

EDIT: The error occurs in a file belonging to eslint. However the rule is turned off for eslint, and when I turn off the typescript-eslint rule the error disappears. So while it is reported in an eslint file it seems to originate from typescript-eslint? eslint was not updated in a month and it all worked -- with daily package updates and package.json set to "*" for all these packages to always get whatever is latest -- until I ran today's update.

TypeError: Cannot set property 'hasAwait' of null
Occurred while linting /home/mha/Projects/core/src/websocket-promisifier.ts:493

TypeError: Cannot set property 'hasAwait' of null
Occurred while linting /home/mha/Projects/core/src/websocket-promisifier.ts:493
    at Object.AwaitExpression (/home/mha/Projects/core/node_modules/eslint/lib/rules/require-await.js:92:36)
    at ReturnStatement (/home/mha/Projects/core/node_modules/@typescript-eslint/eslint-plugin/dist/rules/require-await.js:68:27)
    at /home/mha/Projects/core/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/mha/Projects/core/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/mha/Projects/core/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/home/mha/Projects/core/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/home/mha/Projects/core/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/home/mha/Projects/core/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at /home/mha/Projects/core/node_modules/eslint/lib/linter/linter.js:936:32

The code at websocket-promisifier.ts:493 is ("function" header is line 492)

function sendFn(type: number, ...args: ReadonlyArray<unknown>): Promise<unknown> {
    return new Promise((resolve, reject) => {
    ...

Another file that has that error has it in a function that has this return statement:

    return (): Promise<void> => {
        if (lastAccessibleObjectsSize < RESUME_THRESHOLD) {
            return Promise.resolve();  // ESLINT ERROR HERE
        }
        ....
    };

eslintrc (top):

module.exports = {
    root: true,
    // eslint recommended defaults can be found in [INSTALL_DIR]/eslint/conf/eslint.json
    extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:@typescript-eslint/recommended-requiring-type-checking',
        'plugin:@typescript-eslint/eslint-recommended'
    ],
    parser: '@typescript-eslint/parser',
    parserOptions: {
        ecmaVersion: 2018,
        ecmaFeatures: {impliedStrict: true},
        project: './tsconfig.json'
    },
    env: {
        es6: true,
        mocha: true,
        node: true,
        browser: true
    },
    plugins: ['@typescript-eslint', 'jsdoc'],
    rules: {
...

Versions

| package | version |
| ---------------------------------- | ------- |
| @typescript-eslint/eslint-plugin | 2.8.0 |
| @typescript-eslint/parser | 2.8.0 |
| TypeScript | 3.7.2 |
| ESLint | 6.6.0 |
| node | 12.13.1 |
| npm | `6.12.1 |

duplicate eslint-plugin

Most helpful comment

Duplicate of #1226

The fix has been merged to master, and will be released monday.
If you need it sooner, please try the canary tag.

All 3 comments

The problem related to base rule - comment. I think the fix will be published in the next ESLint release.

cc @bradzacher

This is all inside functions though — I'm not using global await.

Furthermore, there is no await at all in those locations, those are no "async" functions but regular functions returning a "traditional" manually created Promise.

Duplicate of #1226

The fix has been merged to master, and will be released monday.
If you need it sooner, please try the canary tag.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

WayneEllery picture WayneEllery  路  3Comments

bradzacher picture bradzacher  路  3Comments

golopot picture golopot  路  3Comments

valerio-battaglia picture valerio-battaglia  路  3Comments

kimamula picture kimamula  路  3Comments