Skip to content

JSDoc type is not narrowing a union (but typescript does)Β #61339

Closed as not planned
@xPaw

Description

@xPaw

πŸ”Ž Search Terms

jsdoc union type narrow

πŸ•— Version & Regression Information

v5.8.2

⏯ Playground Link

https://www.typescriptlang.org/play/?filetype=js#code/PQKhCgAIUgBAXApgWwA4BsCGTIBUowICeqiAJogGaQDeAgqgJYBSAzgPYB2AogE6-tekAD6QGLDpwAi2TAB5cAPgC+Ypmy4AlRK1RdWiAsHDhQEaHCRosOfBeKkK1GgHkARgCtEAY3irxGtKyBHCoAqS88ES08LwAroiqrHHe3jqsIbBh7BFRtLiqZMHQxqZgmVGOVLTuXr7+6pJ8AryZ2bnRNJSY6AZJKWmsGfbtiJGdrLGMnADmqmMtRiaUiPDeABYAFJAA5Jg7kACU4AB08OuInNu8OnqcBpAAvIqQN7r6iCcekpuHR6fnS7bMyWEiIWibIrwTAALjUEi0tw+ckmvGmM0Uf2ekEwnCIqhAwEgUMwT0U4BoUEg1MYlG2AEISSdkql0v9qdTKRzuZBvPp2OhPuh2DNtkyFoIjgBuKk816rOK8Tgy7nKEzcgBumCEAGsnsTZCcSTLVIcpUA

πŸ’» Code

Typescript version: https://www.typescriptlang.org/play/?&filetype=ts#code/CYUwxgNghgTiAEAXAngBwQQVQSwFIGcB7AOwCUR9UT8QAeAFQD54BeeLPI4gURhkJjwAPuxwESAESiIoDRgG4AUItCRYCbMUQgYAMyhhMYrlJlz4Ab0Xwb8fAFcwh-PgBcSGPZBLb8YNKh3eiUAX2VVaDh4TW09AyNOEl5+QStfBycKN3h9CBofWx0U93xEGE0Ac1DlXRBEMAALAAp4AHIoVvgASkUAOkQGkGIWuEpqBBZmUapiGl6AKy4mru6+gaGWlv8Zdw5xMgoZmlpS8uIK5hXJxTTbbF0WgEJtqF6M53xV31vfGzBqQgQEC9CCECpbAK9IoCboFX7wOCIewwYhw+Bhay2ABusHgAGtWH5IS9QrCgA

πŸ™ Actual behavior

Property 'error' does not exist on type 'ApiJsonResponse<string>'.
Property 'error' does not exist on type 'ApiJsonData<string>'.

πŸ™‚ Expected behavior

No error, and for the type to be narrowed correctly.

Additional information about the issue

In my actual code, I have the types (same as in the typescript playground link), in a d.ts file. I simply converted them to jsdoc comments for the playground.

It does correctly narrow, if I change it to if( data.success === false )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions