Skip to content

StrictNullCheck incorrectly prevents the use of the indexed access operator #20141

Description

TypeScript Version: 2.6.1

Code

class Klass {
  prop1:{innerNumber:number} | null;
  setInnerNumber(newInnerNumber:Klass['prop1']['innerNumber']){
    this.prop1 = {innerNumber:newInnerNumber}
  }
}
//Compile with --strictNullCheck

Expected behavior:
No error.

Actual behavior:
Property innerNumber does not exist on type '{ innerNumber:number;} | null'

Strict null check should not be checked for indexed access operator.

Activity

  1. ghost marked this as a duplicate of Non-null assertion type operator ! #14366 on Nov 19, 2017
  2. ghost added
    DuplicateAn existing issue was already created
    on Nov 19, 2017
  3. typescript-bot commented on Dec 4, 2017

    @typescript-bot
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  4. mhegazy commented on Mar 2, 2018

    @mhegazy
    Contributor

    This should be doable today using NonNullable type

  5. locked and limited conversation to collaborators on Jul 3, 2018
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

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions