microsoft / microsoft/typespec
[Bug]: `Namespace` seemingly has no way to get interspersed type members of different kinds in source code order
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
### Describe the bug
For example, if I have:
```tsp
scalar Scalar1 is extends string;
model Model1 {}
scalar Scalar2 is extends string;
model Model2 {}
```
Then there's seemingly no way to get an array of `Type` objects from the `Namespace` that gives me the scalars and models in the right interspersed order. I can get the scalars in order (via `namespace.scalars`) and the models in order (via `namespace.models`), but I have no way to know how the scalars and models were placed relative to each other.
The same applies to all other kinds (e.g. unions, nested namespaces, decorator declarations, etc.). Ideally I could do `namespace.types` and get the list of top-level types so I can emit generated code that reflects the order of types in the TypeSpec file.
Maybe there is a way and I haven't found it. If that's the case, then maybe it should be more obvious.
### Reproduction
See above.
### Checklist
- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
Contributor guide
Assessment
This issue has not been assessed yet.