Skip to content

Bug: [no-misused-promises] Cannot read properties of undefined (reading 'flags') #5807

Closed
@jlowcs

Description

@jlowcs

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=4.8.4&sourceType=module&code=GYVwdgxgLglg9mABAcwKZQJJjKgTgNQEMAbEVACgDprDdkBnALkV1UIBMFiBPRAbQC6ASmbh2qYDBzsA3AChQkWAhTosOAiTJUadJizacwPfvSi4pyYaLDjJ0+YujwkaTNjxFSFapQD6tAzMrBxcvGYWYMiCIohiElKo7IgA3nKIBlAguEjx9knyAL5ycqgAHgAOcLhQiE7Kruhe2rF5iclpGaxZOaruGs0UAOSEQ0JFQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oFtLlZkiACa1i0Dr0GoMAbXDYciaOOiQANPIVYF2SGQAWiMgGtkANQ6UhAJUT5Y0JukyadOAIb58VAEax8KM4AZu7wgq4KAL4RYNEKALry0ZFAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

function getInnerValue(...args: readonly []): undefined;
function getInnerValue(...args: readonly [string]): undefined;
function getInnerValue(..._args: readonly string[]): undefined {
  return undefined;
}

export function getValue(): undefined {
  return getInnerValue('a');
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/no-misused-promises": [
      "error",
      {
        "checksVoidReturn": {
          "attributes": false
        }
      }
    ]
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

eslint runs without error

Actual Result

TypeError: Cannot read properties of undefined (reading 'flags')
Occurred while linting <input>:8
Rule: "@typescript-eslint/no-misused-promises"
    at SU.isUnionType (https://typescript-eslint.io/sandbox/index.js:20:512744)
    at Object.c [as unionTypeParts] (https://typescript-eslint.io/sandbox/index.js:20:515201)
    at https://typescript-eslint.io/sandbox/index.js:20:893906
    at m2 (https://typescript-eslint.io/sandbox/index.js:20:893955)
    at https://typescript-eslint.io/sandbox/index.js:20:900093
    at d (https://typescript-eslint.io/sandbox/index.js:20:900175)
    at https://typescript-eslint.io/sandbox/index.js:20:258820
    at https://typescript-eslint.io/sandbox/index.js:20:249337
    at Array.forEach (<anonymous>)
    at Object.emit (https://typescript-eslint.io/sandbox/index.js:20:249325)

Additional Info

The issue seems to be coming from the function being defined in a polymorphism manner with rest args.

For instance, this produces the error:

function getInnerValue(...args: readonly []): undefined;
function getInnerValue(...args: readonly [string]): undefined;
function getInnerValue(..._args: readonly string[]): undefined {
	return undefined;
}

export function getValue(): undefined {
	return getInnerValue('a');
}

But this does not:

function getInnerValue(args: readonly []): undefined;
function getInnerValue(args: readonly [string]): undefined;
function getInnerValue(_args: readonly string[]): undefined {
	return undefined;
}

export function getValue(): undefined {
	return getInnerValue(['a']);
}

And neither does this:

function getInnerValue(...args: readonly string[]): undefined {
	return undefined;
}

export function getValue(): undefined {
	return getInnerValue('a');
}

Versions

package version
@typescript-eslint/eslint-plugin 5.40.0
@typescript-eslint/parser 5.40.0
TypeScript 4.8.4
ESLint 8.15.0
node 18.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions