Repository: TypeScript
Issue: JSDoc @enum namespace type support
Labels: Suggestion,Awaiting More Feedback

# Suggestion

<!--
  Please fill in each section completely. Thank you!
-->

## 🔍 Search Terms

<!--
  💡 Did you know? TypeScript has over 2,000 open suggestions!
  🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.
  The "Common Feature Requests" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests

  Replace the text below:
-->

JSDoc

## ✅ Viability Checklist

<!--
   Suggestions that don't meet all these criteria are very, very unlikely to be accepted.
   We always recommend reviewing the TypeScript design goals before investing time writing
   a proposal for ideas outside the scope of the project.
-->
My suggestion meets these guidelines:

* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [x] This wouldn't change the runtime behavior of existing JavaScript code
* [x] This could be implemented without emitting different JS based on the types of the expressions
* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).


## ⭐ Suggestion

<!-- A summary of what you'd like to see added or changed -->

```js
// file: src/a.mjs

/**
 * Enum for BOOL values.
 * @enum { typeof BOOL.TRUE
 *       | typeof BOOL.FALSE }
 */
export const BOOL = /** @type {const} */ ({
  TRUE: 1,
  FALSE: 0,
});
```

// file: jsconfig.json
```json
{
    "include": ["src/**/*"],
    "compilerOptions": {
        "strict": true,
        "noEmit": false,
        "declaration": true,
        "emitDeclarationOnly": true,
        "outDir": "dist",
        "lib": ["ESNext"]
    }
}
```

run

```sh
yarn add --dev typescript
node_modules/.bin/tsc --project jsconfig.json
```

You'll get file dist/a.d.mts

```ts
export type BOOL = typeof BOOL.TRUE | typeof BOOL.FALSE;
export namespace BOOL {
    const TRUE: 1;
    const FALSE: 0;
}
```

I want to change dts file to

```ts
export type BOOL = typeof BOOL.TRUE | typeof BOOL.FALSE;
export namespace BOOL {
    type TRUE = 1;
    const TRUE: 1;
    type FALSE = 0;
    const FALSE: 0;
}
```

## 📃 Motivating Example

<!--
  If you were announcing this feature in a blog post, what's a short explanation that shows
  a developer why this feature improves the language?
-->

## 💻 Use Cases

<!--
  What do you want to use this for?
  What shortcomings exist with current approaches?
  What workarounds are you using in the meantime?
-->

We can change js file from
```js
/**
 * @enum { typeof BOOL.TRUE
 *       | typeof BOOL.FALSE }
 */
export const BOOL = /** @type {const} */ ({
  TRUE: 1,
  FALSE: 0,
});

/**
 * @typedef { { loading: typeof BOOL.TRUE }
 *          | { loading: typeof BOOL.FALSE, data: any }
 * } AjaxStatus  
 */
```

to

```js
/**
 * @enum { BOOL.TRUE
 *       | BOOL.FALSE }
 */
export const BOOL = /** @type {const} */ ({
  TRUE: 1,
  FALSE: 0,
});

/**
 * @typedef { { loading: BOOL.TRUE }
 *          | { loading: BOOL.FALSE, data: any }
 * } AjaxStatus  
 */
```