This is presumably due to the fact that lang-typescript was not available in the mod dropdown menu of syntax highlighting options
Unfortunately, this is only a partial piece of the puzzle here. Due to limitations of the current highlighting implementation on Stack Overflow (read as: one that desperately needs improvement), reality here is more complicated than it first appears.
I don't think changing the highlighter would necessarily be a bad change to (finally) make– just that there's more to bring up here first.
Primer on Tag Highlighting
As a primer for the unfamiliar, general syntax highlighting on Stack Overflow is driven largely through tag usage on questions. Tags can have a specific highlighter specified to match their topic's language.
E.g. for javascript:
Having a language defined means that questions tagged with javascript will automatically have code blocks in their body set to use the lang-js
highlighter.
The problem, however, arises when a question is tagged with multiple tags with non-matching highlighter definitions– for example, javascript and html (the latter is set to lang-html
). Stack Overflow's current solution to resolve such conflicts is simply to throw it all away, and use default
, language auto-recognition based on code syntax, instead.
For substantial-enough code samples in the right languages, this works fine enough, but the point stands that the current configuration simply throws away the specified highlighters and starts from scratch.
Regarding typescript and lang-js
If we set typescript to use lang-typescript
instead of its current setting (lang-js
), then all questions tagged with typescript and another tag set to use lang-js
would simply start using default
, rather than using lang-typescript
as the setting implies.
When you factor in the top 3 tags related to typescript that also have lang-js
as their highlighter (javascript, reactjs, & node.js repectively), this phenomena would affect ~74k questions at time of writing (~40% of all typescript questions).
In a post over on Meta.SE from September of '20, @animuson explains this situation and then argues that keeping things the way they are is the best option currently:
...
Because the javascript tag would be set to lang-js
, setting the typescript tag to lang-typescript
would only cause that huge portion of questions [tagged with both] to revert to default highlighting, and not get highlighted as either JavaScript or TypeScript, which is not ideal. If TypeScript highlighting is better for a particular question, you can manually specify it for that code block. But overall, leaving the typescript tag as lang-js
is far more beneficial ...
Moving Forward
It's a bit of a toss up. Currently, this highlighter mismatch issue affects at least roughly ~40% of typescript questions, which means swapping the highlighter would leave those posts to fend for themselves with the default highlighter. I don't have a good understanding of what sort of impact this would have.
For the other 60%, it's hard to say how much highlighting would really improve, since the lang-ts
highlighter is an adjusted superset of the lang-js
one. That certainly isn't to devalue having the correct highlighter for TypeScript code, since it very much does matter in many cases; just worth acknowledging that it also doesn't matter in a lot of cases as well.
I think this really hinges on whether setting the 40% to default
would have a negative impact or not. If that won't matter that much, then I'd vote for moving forward with this change. I'm not really sure how to efficiently get an answer to that question, however.
lang-typescript
as the default for typscript. The posts I check with both typescript and javascript started using Go syntax highlighting, which seemed substantially more disruptive than usinglang-js
, which is at least closer. It's a sad statement that the syntax highlighting is still so poorly handled 2 years after the switch to highlight.js. Hopefully, SE will actually fix things.