Skip to content

[JS] null is ignored when using in js file #40804

@ericchanky

Description

@ericchanky

TypeScript Version: 4.0.3

Search Terms:

Code

// @ts-check

/**
 * @param {string} x
 * @returns {number | null}
 */
const nullableFunc = (x) => {
    if (/\d+/.test(x)) { return Number(x) }
    return null
}

const a = nullableFunc('123')

Expected behavior:
The type of a should be number | null

Actual behavior:
The type of a is number only

VS code
image
image

Playground Link:
playground

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions