Skip to content

Calling a function that returns never, not always triggers an unreachable code errorΒ #53510

Closed
@gabrielricardourbina

Description

@gabrielricardourbina

Bug Report

πŸ”Ž Search Terms

  • return never
  • unreachable code

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about return never & unreachable code

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare const blue : (...args: any) => never
declare const hof: (fn :(a: (...args: any) => never) => void ) => void

const withBlue = ()=> {
    blue("test")
    return "OK" // Unreachable code detected
}

const withPink = (pink : (...args: any) => never)=> {
    pink("test")
    return "OK" // Unreachable code detected
}

const withGreen = (unk: unknown) => {
    const green = unk as (...args: any) => never
    green("test")
    return "OK"// Unreachable code NOT detected
}

hof((self)=>{
    self("nahh")
    return "Ok" // Unreachable code NOT detected
})

πŸ™ Actual behavior

When the function that returns never is inferred, it does not detect unreachable code
When the function that returns has been type-asserted, it does not detect unreachable code

πŸ™‚ Expected behavior

Calling a function that returns never should render all code bellow unreachable

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions