Skip to content

Question: Should let array = [] really mean we want a never[] instead of any[] or is it just my compiler options? #18687

@SMotaal

Description

@SMotaal

TypeScript Version: 2.5.2

Code

let array = [];
array.push(1); // tsc error: 1 is not never;
console.log(array);

Compiler Options

{
  "target": "es2017",
  "module": "commonjs",
  "strict": true,
  "noImplicitAny": false,
  "noImplicitThis": false,
  "moduleResolution": "node",
  "experimentalDecorators": true,
  "emitDecoratorMetadata": true
}

Expected behavior

» tsc⏎

# a pause of nothingness

Actual behavior

» tsc

2 array.push(1); // tsc error: {} is not never;
             ~

example.ts(2,12): error TS2345: Argument of type '1' is not assignable to parameter of type 'never'.

Potential causes

After some testing, I did pinpoint the culprit behind this problem in my compiler options:

  "noImplicitAny": false

It seems that setting noImplicitAny to true does not suffer from this issue but for some reason false seems to result in the opposite effect of what is expected.

So in my opinion, somewhere in related to parsing this particular compiler option there might be some assumption related to the various possible values for the tri-states of noImplicitAny.

Sample Project:

typescript-empty-array-issue.zip

» yarn && yarn build

Thanks!

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