Closed
Description
TypeScript Version: 4.2.0-dev.20201222
Search Terms: undefined any array
Code
In .ts everything is ok:
const a = [1, 2, undefined, 3]
const isUndef = (v: unknown): v is undefined => v === undefined
// OK: undefined[]
const b = a.filter(isUndef)
.js:
const a = [1, 2, undefined, 3]
/** @type {(v: unknown) => v is undefined} */
const isUndef = v => v === undefined
// Expected: undefined[]
// Actually: any[]
const b = a.filter(isUndef)
Expected behavior:
Variable b
has type undefined[]
Actual behavior:
Filter method returns undefined[]
, but variable b
has any[]
type