TypeScript 5.1 was announced on 1 June 2023. In JavaScript terms it relaxed two rules: a function whose JSDoc says it returns undefined no longer needs a return statement, and a getter and setter can have unrelated types when both are annotated.
Editors gained snippet completions for @param tags in .js and .ts files, JSDoc-heavy files parse faster, and an explicit typeRoots no longer searches parent folders.
At a glance
| Release | TypeScript 5.1 |
|---|---|
| Released | 1 June 2023, the day of its announcement on the TypeScript blog |
| Source | TypeScript 5.1 release notes |
| Examples | Every example runs through TypeScript 5.9.3 when this site is built. |
| Previous release | TypeScript 5.0 |
| Next release | TypeScript 5.2 |
What changed for JavaScript
Returning undefined without a return statement
Before 5.1, only functions returning void or any could end without return. Now a function with @returns {undefined}, or one passed where a function returning undefined is expected, can too.
/** @returns {undefined} */
export function reset() {
console.log("reset");
}
/** @type {() => undefined} */
export const noop = () => {};jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": [
"*.js"
]
} Unrelated getter and setter types
TypeScript 4.3 allowed a setter to accept more than its getter returns, but the getter's type still had to fit the setter. 5.1 drops that rule when both accessors have explicit types: in JavaScript, @returns on the getter and @param on the setter.
export class Label {
#text = "";
/** @returns {{ text: string, length: number }} */
get value() {
return { text: this.#text, length: this.#text.length };
}
/** @param {string} next */
set value(next) {
this.#text = next;
}
}
const label = new Label();
label.value = "Sale";
console.log(label.value.length);jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": [
"*.js"
]
} Snippets for @param
Typing @param in a JSDoc comment offers a completion that fills in the tag for each parameter, in .js files as well as .ts. It is an editor feature; nothing changes for tsc.
typeRoots in module resolution
When an import cannot be resolved the usual way, TypeScript now also looks in the typeRoots folders. And, as a breaking change, an explicit typeRoots no longer falls back to walking up parent folders for node_modules/@types: list every folder you need, including a monorepo root's.
Faster JSDoc parsing
The scanner hands the parser larger pieces of JSDoc comment text, a change the release notes say roughly halves parse time for very large, comment-heavy JavaScript files.
What did not change
An unannotated function with no return is still inferred to return void.
Upgrade notes
From the breaking changes:
- TypeScript itself needs Node.js 14.17 or later.
- A config with
typeRootsmay report TS2688 for types it used to find in a parent folder; add that folder totypeRoots.
Gotchas
- The relaxed accessor rule needs both types written out; with an inferred getter, reading the property right after assigning through the setter can show the assigned type instead.
Sources
- TypeScript 5.1 release notes · TypeScript handbook
- Announcing TypeScript 5.1 · TypeScript blog
Last reviewed 20 October 2026.