With a quick search I can see that the `in-dexter` package [1] provides something quite similar, though I'm not sure if it covers all usecases.
If you want to handroll this yourself you can probably have your `index` emit some `metadata` [2] which you can then `query` [3] for in your `printindex`. All of this would work inside the typst compiler and there would be no need for running an external `makeindex` command.
[1]: https://typst.app/universe/package/in-dexter
[2]: https://typst.app/docs/reference/introspection/metadata/