-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix(43030): undefined[] converted to any[] in JS #43933
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
Conversation
Now I really don't understand the subtleties here. |
@DanielRosenwasser I think this issue is a little bit tricky. The problem here is that for /** @type {() => undefined} */
function f1() {
return undefined;
}
const a = f1()
>a : any
>f1() : undefined
>f1 : () => undefined /** @type {() => null} */
function f1() {
return null;
}
const a = f1()
>a : any
>f1() : undefined
>f1 : () => undefined For instance for a similar case for arrays (line Or use // @strictNullChecks: false
/** @type {() => undefined} */
function f1() {
return undefined;
}
const a = f1()
>a : any
>f1() : undefined
>f1 : () => undefined // @strictNullChecks: true
/** @type {() => undefined} */
function f1() {
return undefined;
}
const a = f1()
>a : undefined
>f1() : undefined
>f1 : () => undefined Does that make sense? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test changes look good. I have some questions about the implementation though. Also, I think we should hold this change for 4.4 in order to make it available to users to test for a long time.
- I looked at the similar code that you pointed out in isEmptyArrayLiteralType, and it only applies to strictNullChecks. Why don't you need the same choice between
=== implicitNeverType
vs=== undefinedWideningType
in this fix? - why
neverType
vsimplicitNeverType
, which is what isEmptyArrayLiteralType uses?
I thought it might be time to revisit the choice of having []: any[]
in strict null checks in js instead of []: never[]
like in TS, but decided that the additional annotations would still not be appropriate for even strict JS. I suspect that switching isEmptyArrayLiteralType to use the check introduced in this PR would get us that. Is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So..making both use the same check doesn't make []: never[]
under strictnullchecks. Interesting, there must be an ad-hoc conversion I've forgotten about. This is a good change for strictnullchecks, since authors probably care about var x = null
having the correct type in that case. We should do some more thinking and maybe usage analysis for the empty array case in the future.
Update: looking closer at the baselines, the conversion must happen for initialisers, because in |
Fixes #43030