Repository: TypeScript
Issue: `@deprecated` nested namespace handling is buggy
Labels: Help Wanted,Possible Improvement

### 🔎 Search Terms

deprecated nested namespace

### 🕗 Version & Regression Information

- This is the behavior in every version I tried

### ⏯ Playground Link

https://www.typescriptlang.org/play/?#code/FAegVGAEACAmCmAHATvAxgQwC71pMIwAdhgLbwDOiGa8kAYgPaMCMAdAEIbKQDewkSPAAeiRsiyQ0jIhUnDIAXkgsA3MAC+wYmUrVaDZuy4AvPgKGjxk6bPlKV6rcCatO3NsPWvjGE5-VtUBAQoJ1yKho6VwAmdzN+QRExCSkZOUgFZTVNbXAoOCRUTBw8AnC9KMNGOK4eRMsUm3T7bKcg2PdkAJdmWr8e7SA

### 💻 Code

```ts

/** @deprecated */
namespace Foo1.Bar {
  export const x = 1;
}

namespace Foo1.Baz {
  export const x = 1;
}

Foo1.Bar.x;
Foo1.Baz.x;
```

```ts
namespace Foo2.Baz {
  export const x = 1;
}

/** @deprecated */
namespace Foo2.Bar {
  export const x = 1;
}


Foo2.Bar.x;
Foo2.Baz.x;
```


### 🙁 Actual behavior

Usages of `Foo1` are stricken through
![image](https://github.com/user-attachments/assets/48abf319-7fb8-471c-ad78-2b906307f62d)

But usages of `Foo2` are not stricken through
![image](https://github.com/user-attachments/assets/6c42382d-169c-4cb3-930a-6bbb1998cdf7)

Yet intellisense shows the tag in the hover for `Foo2`
![image](https://github.com/user-attachments/assets/755ecc07-cd6e-4a40-bd14-32995d00830a)


### 🙂 Expected behavior

Either both `Foo1` and `Foo2` should be treated as deprecated, or neither should and instead the `Bar` in `Foo1.Bar` and `Foo2.Bar` should be treated as deprecated.

### Additional information about the issue

@typescript-eslint recently released a new lint rule [`no-deprecated`](https://typescript-eslint.io/rules/no-deprecated/) which reports a lint error whenever you use a thing marked with `@deprecated`.

A user mentioned to us that the rule reports incorrectly in certain cases (https://github.com/typescript-eslint/typescript-eslint/issues/9902).

Specifically in a case like this
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d1c172bdcfd4508405f4b233e11ccd7d8743f763/types/chrome/index.d.ts#L8553-L8556

We did some investigation and found that things can be pretty ambiguous when nested namespace declarations are marked `@deprecated` like this and TS itself struggles with it.

---

It's worth noting that the above behaviour [is consistent between nested namespace shorthand (`namespace Foo.Bar`) and the non-shorthand style](https://www.typescriptlang.org/play/?#code/FAegVGAEACAmCmAHATvAxgQwC71pMIwAdhgLbwDOiGa8kAYgPaMCMkA3sJJPAB6KNkWSCXJUadAEIZkHLtx79BwtIyIVhvSAF5ILANzyAvsBPEylarQbM2nbnwFCRF8dekAvOQsVOVajUgtXQNjU2BgJlYAOmlkaN5DKJZYjA8EwwjQEBys8zErOiiAJm9fZRcCiUhPMoclZ1V1TR09Q24TM3AoOCRUTBw8AnzLapKyxwrRUfcZOvLGgJaQ9shOrJLU+MTI5mLU9J2IoA)

Note you see similar behaviour for many declaration-merged things where TS's handling only makrs something as deprecated if the first definition is marked as deprecated, eg [Enums](https://www.typescriptlang.org/play/?#code/N4KABGCmB2CuC2YBiB7FZQQgQTAXjAEYAacMAXzIHoAqGsAAQBNIAHAJ0gGMBDAF0hMwNKmRgJkaDGQgAhfGABMpCJTJcU0AM58wADwWoUAOmwBudZp1gAnobTHZFtVVcgQmMLXrM2nXgJCImJwiEbSWGC4BCRklBDiYVKecgrKce6W2roGBEamFhAa2bb2Jk4glEA).

But there are also cases where TS gets it right, eg [Interfaces](https://www.typescriptlang.org/play/?#code/N4KABGCWB2AuCmAnAZgQwMbzAMQPa7FAggEEAuMARgBpwwBfOgegCoWwABAE3gAdF46VAi5gWTOjAQoMWPASLEAQhQBMtCIzqwAnrywAPMAF4c+ANoByEpYC6Abm16sOk2dxWldx1qZ+QIIqs7Nx8AkIiYhIQUkhomO6EdKQUNHSMMXBxsomKECpg6ukBTvpgRqbyVjYOpS5uVZZetYxAA)

Then there are weird cases like [type/value shadowing](https://www.typescriptlang.org/play/?#code/N4KABGDGD2B2DOAXMAxa0wF4yghAggFxgCMANOGAL4DclA9AFSNgACAJgKYAOATp5ACGiTuzCN6lAJawRvAGaDInVOhyUIAIWIAmChCohKMBMgAeWVdADaAcny2AunQiIAntxVvLaG7c1OdIYg9KFGuGBMLBw8-EIiYhLGcEhWlhEExOSUtNKynApKKr7qeGDaYHo5RsmmYBbYvnYOzpTunmDejeh2Aa2GQA) where I'm not sure if TS is right or wrong -- depends on what you expect I guess.

---

I would love to see some clarification on what you guys think is the correct behaviour so that we can follow-suit!