Skip to content

undefined[] converted to any[] in js #42133

Closed
@awerlogus

Description

@awerlogus

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issuecheckJsRelates to checking JavaScript using TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions