๐ 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