Skip to content

The new NonNullable type doesn't work the same when combined with index typesΒ #50462

Closed

Description

Bug Report

πŸ”Ž Search Terms

NonNullable index

πŸ•— Version & Regression Information

  • This changed between versions 3.7.4 and 3.8.1-rc

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Edge<Typename extends string = string> = {
  readonly events: ReadonlyArray<{ readonly __typename: Typename } | null>;
};

export type InnerEventTypename<EdgeT extends Edge> = NonNullable<EdgeT['events'][number]>['__typename'];

πŸ™ Actual behavior

Error: Type '"__typename"' cannot be used to index type 'NonNullable<EdgeT["events"][number]>'.

πŸ™‚ Expected behavior

No error.

Activity

  1. RyanCavanaugh commented on Aug 26, 2022

    @RyanCavanaugh
    Member

    Simplified

    type A = {
        prop: { x: string, y: string } | null
    };
    // 4.7: OK
    // 4.8: Error
    type Test<T extends A> = NonNullable<T['prop']>['x'];
  2. ahejlsberg commented on Aug 26, 2022

    @ahejlsberg
    Member

    This was an issue only in 4.8.0-beta. It was fixed in 4.8.1 and doesn't currently repro.

  3. added
    FixedA PR has been merged for this issue
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Aug 26, 2022
  4. RyanCavanaugh commented on Aug 26, 2022

    @RyanCavanaugh
    Member

    I oversimplified, then. This is (newly) erroring in 4.8.2

    type Column<T = unknown> = (keyof T extends never ? { id?: number | string } : { id: T }) & {
        title?: string;
    }
    
    // no error if `key: keyof Column`
    function getColumnProperty<T>(column: Column<T>, key: keyof Column<T>) {
        return column[key];
    }
  5. RyanCavanaugh commented on Aug 26, 2022

    @RyanCavanaugh
    Member

    Actually since OP is fixed, let's track over at that one - #50465

  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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