Skip to content

Typescript/Javascript doesn't correctly pick up type information when the type is a union with undefined or nullΒ #61932

Open
@desean1625

Description

@desean1625

πŸ”Ž Search Terms

"JSDoc","@type","union"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250624&filetype=js#code/LAKFoegKigCABALgTwA4FNYG8DOiBOAlgHYDmsAPrAK7EAm6AZienQL6xQSgBuAhvhrFCAe2IB9AO6FEAC3G0GzYqwDc4EI1oBjRKOKwtxbQApocJGky4CJclUVMW7ThFixUAvgFsAlNjZ1MGDzBBQMbDwiMkpYYmpvACN0fA4uXgFYKLtxeKSUhWExIKA

πŸ’» Code

/** @type {string | undefined} */
var union_with_undefined;

function func(/** @type {string | undefined} */  param) {};


/** @type {string | number} */
var string_number_union;

πŸ™ Actual behavior

/** @type {string | undefined} */
var union_with_undefined; //This is type string

πŸ™‚ Expected behavior

/** @type {string | undefined} */
var union_with_undefined; //This is type string|undefined

Additional information about the issue

/** @type {string | undefined} */
var union_with_undefined; //This is type string

Image

function func(/** @type {string | undefined} */ param) {}; //The function has the correct signature, but inside the function the param is type string

Image

/** @type {string | number} */
var string_number_union; //Unions with anything things that are not null/undefined are correctly typed

Image

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