🔎 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
🔎 Search Terms
Never, return type never
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/DYUwLgBAhgXBDOYBOBLAdgcwgHwgVzQBMQAzdEQgKFEgCM5FVMd8jTyqaIBjB5dLLgLEyaCpUrcA9mkTQSEALwQAFAEolAPggBvShAMQwACyRSA7hDGWAokjNJ1lAL6SZc2guXq4YgG4gSFq6+oYmZpbWEHYOTq7SspDcJHDqwf6BSqoaitp6hkamFlYgtvZSjmouEmAAngAOIEYgiACCAGJZAErgeEhoACoNIAA8dY1SClAkmpQA9HOGAHoA-JTjTWAtYABCnco9YH2Dw2PDkxCeswvLaxvNiADC+xCHx0ONZxMKydeLBqsJJQUAoVABCKAaabqADclCgADpQJgTBIQaowbQNJ5YZRaEiQCjjBA0aCwdwNMlcdwCUSIEA
💻 Code
🙁 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