typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Evolving arrays don't work in JS

Open jakebailey opened this issue 6 months ago • 3 comments

const foo = []

for (let i = 0; i < 10; i++) {
    foo.push(i)
}

console.log(foo)

Nets:

Argument of type 'number' is not assignable to parameter of type 'never'. ts(2345)

Image

jakebailey avatar May 30 '25 16:05 jakebailey

JS now works like TS; evolving types work with noImplicitAny true, but do not with it false. I think this is a decent restriction because anything that makes JS behave more like TS is good in my book.

On the other hand, locking evolving arrays behind noImplicitAny was originally an ad-hoc decision to prevent people with noImplicitAny:false from switching from 0 errors to some errors. So there's no real reason for it to be noImplicitAny-only in TS either.

I'll leave this bug open till I have a chance to think more about what the right thing is.

sandersn avatar Aug 08 '25 16:08 sandersn

noImplicitAny isn't enabled by default in LS implicit projects, only strictNullChecks and strictFunctionTypes.

jakebailey avatar Aug 08 '25 16:08 jakebailey

This doesn't repro with the error message. Rather, the repro succeeds with foo having type any[] when noImplicitAny is false and type number[] when noImplicitAny is true. So, as @sandersn states above, JS now behaves like TS in Corsa. In Strada, we always compute evolving types in JS files, even when noImplicitAny is false. Thus, in Strada, foo always has type number[].

We need to decide if we want to keep this difference or align with the Strada JS behavior.

ahejlsberg avatar Nov 07 '25 19:11 ahejlsberg