TypeScript rationalizes undefined-returning functions

InfoWorld | at | by Mike

TypeScript 5.1, available in a beta release as of April 18, features a variety of coding enhancements including easier implicit returns for undefined-returning functions and allowing unrelated types for getters and setters. Snippet completions for @param JSDoc tags also are featured.With easier implicit returns for undefined-returning functions, TypeScript 5.1 now allows undefined-returning functions to have no return statement, fixing a situation in which only functions that could have absolutely no return statements were void-returning and any-returning functions. This meant that even if a developer explicity indicated that a function returned undefined, at least one return statement was required.This was a problem if an API expected a function to return undefined, in which case at least one explicit return of undefined or a return statement and an explicit annotation was needed. This behavior was confusing and frustrating, Microsoft said. Also with TypeScript 5.1, if a function has no return expression and is being passed to something that expects a function to return undefined, TypeScript infers undefined for that function’s return type.