const a = false || []
// ^?
const b = []
// ^?
function c() {
// ^?
return []
}
const d = c()
// ^?
More interactions:
let b = false || []
// ^?
const a:number[] = b
const c:string[] = b
b = a // error as expected
b = c // expect as expected
let b1 = []
// ^?
const a1:number[] = b1 // did not expect error but error
const c1:string[] = b1 // did not expect error but error
b1 = a1
b1 = c1
// with type annotation
let b2:any[] = []
// ^?
const a2:number[] = b2
const c2:string[] = b2
b2 = a2
b2 = c2
playground
The behavior of inferred any[] is very interesting, the declaration and assignment both error when we attempt to assign it
Turn out the inferred any[]
type if not really an any[]
type, it is an evolving type
Top comments (0)