Skip to content

Add strict check for undefined properties on an object #357

Open
@dib542

Description

@dib542

There is a common TypeScript issue where a property on an object is assumed to exists.

      // allUserTokensList is type Token[]
      const tokenIndex = allUserTokensList.findIndex(matchTokenDenom(denom));
      // token is of type Token not Token | undefined
      const token = allUserTokensList[tokenIndex];

This is a long and divisive issue in TypeScript microsoft/TypeScript#13778 because flagged all items found by index can be problematic in many places that they are expected to be known. However as a resolution, a --noUncheckedIndexedAccess flag can be used to turn on checking for this.

This has caused runtime errors in the past and I would prefer to be able to see these errors if feasible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions