Skip to content

Incorrectly inferred type never for variables with strictNullChecks #9322

Closed

Description

TypeScript Version:

nightly (1.9.0-dev.20160623-1.0)

Code

let foo = [];
foo.push('x');

Expected behavior:

No errors, TypeScript should infer the type any[] for the variable foo.

Actual behavior:

tsc without any command line option behaves as expected, but when used with --strictNullChecks it emits the error:

foo.ts(2,10): error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.

Activity

  1. aluanhaddad commented on Jun 24, 2016

    @aluanhaddad
    Contributor

    Working in 1.9.0-dev.20160624-1.0

  2. RyanCavanaugh commented on Jun 24, 2016

    @RyanCavanaugh
    Member

    Failing for me as described in current master

  3. aluanhaddad commented on Jun 24, 2016

    @aluanhaddad
    Contributor

    Ryan Cavanaugh (@RyanCavanaugh) I had misconfigured project. I can indeed reproduce the error. Sorry for the confusion.

  4. ahejlsberg commented on Jun 29, 2016

    @ahejlsberg
    Member

    This is working as intended. The inferred type for foo is never[] because we don't widen types in --strictNullChecks mode. Full details in #8944.

  5. added
    Working as IntendedThe behavior described is the intended behavior; this is not a bug
    and removed
    BugA bug in TypeScript
    on Jun 29, 2016
  6. locked and limited conversation to collaborators on Jun 19, 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

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions