Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly inferred type never for variables with strictNullChecks #9322

Closed
e98cuenc opened this issue Jun 23, 2016 · 4 comments
Closed

Incorrectly inferred type never for variables with strictNullChecks #9322

e98cuenc opened this issue Jun 23, 2016 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@e98cuenc
Copy link

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'.
@aluanhaddad
Copy link
Contributor

Working in 1.9.0-dev.20160624-1.0

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 24, 2016
@RyanCavanaugh
Copy link
Member

Failing for me as described in current master

@aluanhaddad
Copy link
Contributor

@RyanCavanaugh I had misconfigured project. I can indeed reproduce the error. Sorry for the confusion.

@ahejlsberg
Copy link
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.

@ahejlsberg ahejlsberg added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Bug A bug in TypeScript labels Jun 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants