· Jake Worth

JSDoc deprecations in TypeScript


Suppose you want to mark a typed attribute as deprecated. Shared and library code comes to mind. We can achieve this with JSDoc’s @deprecated, which has TypeScript meaning, too. Here’s an example.

App.tsx
interface User {
fullName: string;
/** @deprecated use fullName field instead */
lastName: string;
}
function App() {
const user: User = {fullName: 'jake worth', lastName: 'worth'};
return <>{user.lastName}</>;
}
export default App;

Text editors with a TypeScript server (you have that, right?) print something like this when hovering on an instance of the deprecated lastName:

"lastName" is deprecated.
Related information:
* App.tsx#5,7: The declaration was marked as deprecated here.
(tsserver 6385)

This is a language-service warning, not a compile error. tsc still succeeds; your editor are what surface it to the team.

JSDoc @deprecated docs
TypeScript JSDoc @deprecated playground