Why are Arrays declared inside Object literals inferred as Never and unable to evolve in Any like in all other cases? I'm thinking Dictionaries pre-seeded with initial values of differing objects.
- 1.1. What's the most convenient/terse/idiomatic solution to typecheck existing JS files with those patterns, with the least refactoring as to keep the project JS-only proper? Is it solved with a different config, and if yes can it apply to floating files outside of a project or specific directory?
- 1.2. Why do
t4andt5work even though the argument to assign is also defined as an object literal? - 1.3. What are the downsides of
/** @type {*} */or/** @type {object} */(which also works) over the inferred type of an open-ended object? Why is that not the default behavior?
Here I added types (generated by Document This) only on errors, and afterward all of these examples pass. No jsconfig.json, official VSCode plugin with default settings.
// @ts-check
"use strict";
const a = []
a.push(1)
/** @type {*} */
const t1 = {
a: [],
}
t1.a.push(1)
/** @type {*} */
const t2 = {
a: {
b: [],
},
}
t2.a.b.push(1)
const t3 = {}
t3.a = []
t3.a.push(1)
const t4 = {}
Object.assign( t4, {
a: []
})
t4.a.push(1)
const t5 = {}
Object.assign( t5, {
a: {
b: []
}
})
t5.a.b.push(1)
/** @type {*} */
const t6 = Object.assign( {}, {
a: []
})
t6.a.push(1)
/** @type {*} */
const t7 = Object.assign( {}, {
a: {
b: []
}
})
t7.a.b.push(1)