You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[] is regard wrong as never[] when strictNullChecks is true #13140
An empty array without a type annotation can not be inferred to have any type. If --strictNullChecks is off, it is inferred to be undefined[] and then widened to any[]. if --strictNullChecks, undefined is not in the domain of any type, so it is not inferred. so you are left with a never[].
Add a type annotation or an intializer to avoid getting a never[].
Why can't we use control-flow analysis so that users get the "smart" behavior that they get with --noImplicitAny?
cause noImplicitAny is set to false in the config file above. if it is set to true, control flow analysis gets the type of output as any[] since obj is any. you will get an error on obj however, since it is implicitly any.
Since I don't see it recorded in the meeting notes, do you recall the justification?
My understanding is that the reason we didn't do it outside of noImplicitAny alone is that it was a breaking change - but if we infer never[] under strictNullChecks, I don't see how this would possibly be a breaking change for any reasonable cases.
Activity
mhegazy commentedon Dec 26, 2016
An empty array without a type annotation can not be inferred to have any type. If
--strictNullChecksis off, it is inferred to beundefined[]and then widened toany[]. if--strictNullChecks,undefinedis not in the domain of any type, so it is not inferred. so you are left with anever[].Add a type annotation or an intializer to avoid getting a
never[].DanielRosenwasser commentedon Dec 26, 2016
Why can't we use control-flow analysis so that users get the "smart" behavior that they get with
--noImplicitAny?mhegazy commentedon Dec 26, 2016
cause
noImplicitAnyis set tofalsein the config file above. if it is set to true, control flow analysis gets the type ofoutputasany[]sinceobjisany. you will get an error onobjhowever, since it is implicitlyany.DanielRosenwasser commentedon Dec 27, 2016
What I mean is: can we change the behavior so that users get similar behavior as if they did enable
noImplicitAnywhen they enablestrictNullChecks?mhegazy commentedon Dec 28, 2016
That was discussed in #12359. and the conclusion was not to do that.
DanielRosenwasser commentedon Dec 28, 2016
Since I don't see it recorded in the meeting notes, do you recall the justification?
My understanding is that the reason we didn't do it outside of
noImplicitAnyalone is that it was a breaking change - but if we infernever[]understrictNullChecks, I don't see how this would possibly be a breaking change for any reasonable cases.mhegazy commentedon Dec 28, 2016
The two bugs listed were the reason. Being a breaking change and causing perf regressions.