Skip to content

Bug: Issue with noUncheckedIndexedAccess and no-unnecessary-type-assertion #11343

Closed as not planned
@Stadly

Description

@Stadly

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.

Issue Description

const users: Record<string, string> = {};
export const getUser = (name: string) => {
  users[name] ??= 'hei';
  return users[name]!; // Error: @typescript-eslint/no-unnecessary-type-assertion
};

const groups: Record<string, string> = {};
export const getGroup = (name: string) => {
  name = `${name}-grp`;
  groups[name] ??= 'hei';
  return groups[name]!; // No error!
};

I expected that the return from both functions should produce the @typescript-eslint/no-unnecessary-type-assertion error. Only the first does. If I remove noUncheckedIndexedAccess, I get the expected behavior.

Reproduction Repository Link

https://stackblitz.com/edit/vitejs-vite-imvtqxsz?file=src%2Ffoo.ts

Repro Steps

  1. Open the StackBlitz
  2. npx eslint .

Versions

package version
@typescript-eslint/eslint-plugin 8.35.0
@typescript-eslint/parser 8.35.0
@typescript-eslint/scope-manager 8.35.0
@typescript-eslint/typescript-estree 8.35.0
@typescript-eslint/type-utils 8.35.0
@typescript-eslint/utils 8.35.0
TypeScript 5.8.3
ESLint 9.29.0
node 20.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageWaiting for team members to take a lookworking as intendedIssues that are closed as they are working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy