Microsoft/TypeScript

Support `@deprecated` marker on namespace aliases

Open

#62.340 aperta il 27 ago 2025

Vedi su GitHub
 (0 commenti) (1 reazione) (0 assegnatari)TypeScript (6726 fork)batch import
Domain: JSDocHelp WantedPossible Improvement

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

🔍 Search Terms

"@deprecated", "deprecated", "namespace", "namespace alias"

✅ Viability Checklist

⭐ Suggestion

Note: Marking this as a feature request, very well might be a bug. It's one of those that are probably up for interpretation?


I'd like the ability to annotate namespace aliases with @deprecated. At the moment you'd need to mark the referenced type as deprecated, which often isn't viable.

Here's a little example:

// @filename: example.d.ts
export type Bar = string | number;

/** @deprecated */
export type Baz = string | number;


// @filename: foo.ts
import * as example from './example';

declare namespace JSX {
	/** @deprecated */
	export type Foo = string | number;

	/** @deprecated */
	export import Bar = example.Bar;

	export import Baz = example.Baz;
}

let x: JSX.Foo;  // Marked as deprecated
let y: JSX.Bar;  // Not marked as deprecated (but should be)
let z: JSX.Baz;  // Marked as deprecated

TypeScript Playground Link

📃 Motivating Example

Allows developers to mark namespace aliases as deprecated, giving downstream users more warning when those aliases will go away.

💻 Use Cases

  1. What do you want to use this for?

preact has long since loaded up the JSX namespace with unrelated types... shouldn't have, but did. We're looking to get rid of this in our next major and to help folks migrate we wanted to extract the types to the preact namespace and re-export them as aliases through the JSX namespace. This will avoid any breaking changes in the current version and allow folks to keep compatibility with v10 and the upcoming v11.

Unfortunately, however, we can't mark this usage as deprecated which is a shame.

  1. What shortcomings exist with current approaches?

Just doesn't work. End users get no warning that the namespace alias is deprecated.

  1. What workarounds are you using in the meantime?

Just duplicated all the types. Instead of extracted types that are consumed both as direct exports and namespace aliases, we've had to make copies. Those in the namespace get the deprecation comment, those outside do not.

It's pretty fragile obviously, any change to one now has to be reflected to the same interface in another file.

Guida contributor