้•œๅƒ็ซ™็‚น ยท ๆœฌ้กต็”ฑ็ฌฌไธ‰ๆ–น GitHub ๅช่ฏป้•œๅƒๆไพ›๏ผŒ้ž GitHub ๅฎ˜ๆ–น็ซ™็‚น๏ผŒไธๆŽฅๅ—ไปปไฝ•็™ปๅฝ•ๆˆ–ๅ‡ญๆฎ่พ“ๅ…ฅใ€‚ๅ‰ๅพ€ github.com
Skip to content

'Never': different behavior with and without function type declaration ย #57084

Description

@HironTez

๐Ÿ”Ž Search Terms

Never, return type never

๐Ÿ•— Version & Regression Information

  • This is the behavior in every version I tried

โฏ Playground Link

https://www.typescriptlang.org/play?#code/DYUwLgBAhgXBDOYBOBLAdgcwgHwgVzQBMQAzdEQgKFEgCM5FVMd8jTyqaIBjB5dLLgLEyaCpUrcA9mkTQSEALwQAFAEolAPggBvShAMQwACyRSA7hDGWAokjNJ1lAL6SZc2guXq4YgG4gSFq6+oYmZpbWEHYOTq7SspDcJHDqwf6BSqoaitp6hkamFlYgtvZSjmouEmAAngAOIEYgiACCAGJZAErgeEhoACoNIAA8dY1SClAkmpQA9HOGAHoA-JTjTWAtYABCnco9YH2Dw2PDkxCeswvLaxvNiADC+xCHx0ONZxMKydeLBqsJJQUAoVABCKAaabqADclCgADpQJgTBIQaowbQNJ5YZRaEiQCjjBA0aCwdwNMlcdwCUSIEA

๐Ÿ’ป Code

let a: string | undefined
let b: string | undefined
let c: string | undefined

const af = () => {
    throw new Error()
}
const bf = (): never => {
    throw new Error()
}
const cf: () => never = () => {
    throw new Error()
}

if (!a) af();
a.length // Error

if (!b) bf();
b.length // Error

if (!c) cf();
c.length // Fine

๐Ÿ™ Actual behavior

Typescript does not check 'never' in condition statements but does if the whole function is declared

๐Ÿ™‚ Expected behavior

The 'never' return type should always behave in the same way

Additional information about the issue

No response

Activity

  1. MartinJohns commented on Jan 18, 2024

    @MartinJohns
    Contributor

    This is working as intended. See #32695 and many many others (e.g. #55351).

  2. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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