2

TypeScript (TS) and JavaScript are related languages, but they are not exactly the same.

It might be valid to answer a TypeScript question with pure JavaScript, but is the reverse ok?

It feels a little like the age-old jQuery only answers to JavaScript questions, except not just an optional library, but a change in the language used.

Here is an example of a (almost) code only answer given in TypeScript. I can pretty much read it without knowing TypeScript, but I can't guarantee it would run if I stripped out all the 'TypeScript bits'.

Is this 'not an answer' ? Should it just be downvoted?

This is (in my opinion) not simply: How should we handle answers in a programming language other than what the OP requested?

The currently most upvoted answer there starts:

It depends on the nature of the question.

The nature of the questions I'm trying to highlight is where no attempt is made to explain how the TypeScript answer relates to the JavaScript code.

The answer even just starts with 'This is the solution', and no mention of TypeScript.

As stated in a comment:

There are two instances of TS specific code there it's (axios as jest.Mocked<typeof axios>) twice. The direct JS equivalent is literally the code axios.

This obviously takes some knowledge of TypeScript to understand, as least as far as I can see. For all I know, I need additional code if I want to translate it into working JavaScript code. Perhaps by specifying the type, Jest handles or mocks Axios differently. Is the onus on me to know the ins-and-outs of TypeScript and how to translate it?

The answer by VLAZ provides an interesting example:

If a subject matter expert in graph theory can supply an optimal answer question tagged only in, say, then we should not discourage them.

I think that's even more of an orange, but at least if they make that clear, the answer has some temporary value. By no means do I think it should be the final or accepted answer, if every subsequent poster has to do that C# -> JavaScript translation. Ideally in this hypothetical case, the OP could/should self-answer with their translation. And suddenly there is not point in keeping the C# answer (it could be deleted, with no issues to the question). Heck, if possible that would have been better as a comment linking to the library elsewhere.


I wanted to get this reopened and self-answer to make it clear my intent, but it seemed better to just make a new post, and self answer there

41
  • 4
    Valid in what way? They're certainly not "not an answer", and including types doesn't make them "very low quality",
    – Kevin B
    Nov 8, 2021 at 15:42
  • 1
    @KevinB I'm definitely not arguing they're 'very low quality', but if the asker isn't asking about typescript, is an answer using typescript actually answering the question? Nov 8, 2021 at 15:47
  • 1
    That isn't "not an answer" by Stack Overflow terms, @Pureferret . Not an answer <> Not a useful answer. "Not an answer" on Stack Overflow means that the post is literally not an answer; it makes no attempt to answer a question, let alone the OP's. An answer that provides a solution in a different language is still an answer; just (likely) not a useful answer.
    – Thom A
    Nov 8, 2021 at 15:50
  • 2
    No, again, an answer in a different language is still an answer. End of Story. Usefulness does not equate, or even relate, to an answer being an answer or not.
    – Thom A
    Nov 8, 2021 at 15:53
  • 1
    @Pureferret Your question asks for a general "Is typescript to javascript valid", the answer there states you should handle it case-by-case which also applies here. There might be some questions that can't be properly answered using typescript because they specifically ask for javascript internals. If you wish to discuss your example case, it'd be different.
    – Erik A
    Nov 8, 2021 at 15:56
  • 1
    OK, I wrote my question without looking at your example. I didn't want to focus on it too much for the answer. Now that I did, I must say I'm very disappointed with the example you chose. There are two instances of TS specific code there it's (axios as jest.Mocked<typeof axios>) twice. The direct JS equivalent is literally the code axios. And you claim this is "not an answer" or "low quality" and in a comment you say you "can't see how this is easily applicable to their use case?". This is borderline claiming that we should only respond with directly copy-pasteable solutions.
    – VLAZ
    Nov 8, 2021 at 15:58
  • 2
    The orange analogy is meant to refer to an answer that doesn't at all resemble an answer. Not answers to another question or a variation of the current question.
    – Kevin B
    Nov 8, 2021 at 16:30
  • 1
    Honestly, I'd suggest the Orange is more that you asked how to achieve X in language Y, and got an answer about how the mechanics of a Steam Engine work. Not how to achieve X in Language Z (which can be implemented in Language Y).
    – Thom A
    Nov 8, 2021 at 16:30
  • 1
    The answerer in this case clearly intended to answer the question asked. This isn't an example of "Your question on javascript testing is great and all, but here's how to fly an airplane."
    – Kevin B
    Nov 8, 2021 at 16:33
  • 1
    "Is the onus on me to know how TypeScript works?" counter-question to this one - if OP does not understand the answer, does that mean that it's not an answer? Followup question - since when is the OP the only user relevant? All the answers written are visible to everybody on the internet. In fact, the whole aim of SO is to not help a single person per answer. The OP of a question is in the extreme minority of people helped by an answer. One person vs potentially everybody else who visits the Q&A.
    – VLAZ
    Nov 8, 2021 at 16:45
  • 2
    I'd also like to remind you that you are currently saying that an answer that uses very slightly different language) is exactly the same thing as spam or a cat walking on the keyboard. These are the staples of NAA. Are you *sure this is the argument you want to go with?
    – VLAZ
    Nov 8, 2021 at 16:48
  • 1
    @OlegValter I've got a passing familiarity, but I've never had to use it. This is the sort of gotcha I could see producing incorrect answers, even though the TypeScript is valid, and implies it should run correctly. Nov 8, 2021 at 19:01
  • 1
    Anyways, I do not think the point about "potential bits that aren't compatible" is invalid as a whole, and I think we should encourage answer authors to provide solutions as close to the original question as possible (including the language used) as for the numerous readers after the OP it is just an unnecessary mental strain and wasted time. I think the best way to approach this is to either comment and ask the person to provide a vanilla alternative or edit it in (especially given that we have the editing privileges). [1/2] Nov 8, 2021 at 19:10
  • 2
    @OlegValter There are no generics in ECMAScript (the big one missed :)). Nov 8, 2021 at 20:41
  • 2
    @HereticMonkey oh, how could I, I guess interfaces count too then :) Nov 8, 2021 at 22:31

1 Answer 1

2

Is this 'not an answer' ?

Big flaming word "NO"

(My apologies, but the Markdown formatting is a bit limited. I am unable to use flaming letters here, so I had to use this image. Thanks to Larnu for supplying it.)

The "Not an answer" flag should be used for things that should not be put in the answer box. That does not mean "technically inaccurate". It does not even mean "I do not like this answer". It means: spam, separate questions, remarks like "I have this problem too", link-only answers, pure gibberish, etc. Things that are not answers because they do not even attempt answering the question as required by the site. Anything that attempts to answer the question is, not surprisingly, an answer.

For more information see the FAQ entry: When to flag an answer as "not an answer"

Should it just be downvoted?

Maybe Big flaming asterisk Two big flaming asterisks

(again due to limitations of Markdown, I could not apply maximum emphasis on the asterisks, so I had to use images.)

* Just because an answer is in another language, does not mean that it is automatically not useful. People can answer questions that are tagged with one language in pseudocode to outline an algorithm to be applied without writing in a specific language. Or they can write C, or Python, or any other language they are more familiar with if it is clear what they mean.

There is no requirement for the answer to be in the same language. Yes, that is the expectation but we are primarily looking for useful answers. Just because somebody wrote an answer in another language does not automatically make it not useful. Indeed, it might be very useful - we want experts to answer. If a subject matter expert in graph theory can supply an optimal answer question tagged only in, say, C# then we should not discourage them. Algorithms are easy to translate. That knowledge is far more valuable than knowing how to write a particular language.

** TypeScript in particular is not even something hard to work into a JavaScript answer. At the very least, anybody can copy/paste the TypeScript code into the online compiler and get the equivalent JavaScript code. It is also very easy to directly translate TypeScript to JavaScript. So, I do not see how a TypeScript answer is not useful. It often reads even easier than JavaScript. Yes, it does rely on a little bit of knowledge of TypeScript (to read the types correctly) but good code should be self-descriptive anyway. Therefore, I would expect good TypeScript code to not be a problem for people with JavaScript background to read. After all, TypeScript should be compatible with JavaScript anyway.

9
  • 2
    Do either of these meet your burning text needs? :) 1 2
    – Thom A
    Nov 8, 2021 at 15:58
  • 1
    @Larnu thank you, I used number 2. I think it better conveys the message I am striving for.
    – VLAZ
    Nov 8, 2021 at 16:18
  • @Larnu on a mostly unrelated note, I seem to have found a bug on that cooltext website. Apparently trying to generate an image of a flaming asterisk symbol doesn't work. Unless there are other symbols present. I can't seem to get one with just an asterisk or two.
    – VLAZ
    Nov 8, 2021 at 16:22
  • It does seem to "not" like it, @VLAZ (I only found the site by Googling "Flaming Text Generator"). Though I did manage to generate one by entering "Maybe \* \*\*" first, and then removing the \ characters
    – Thom A
    Nov 8, 2021 at 16:27
  • I've updated my question to more clearly state my issue Nov 8, 2021 at 16:28
  • @Larnu no, I mean it works if there is any other symbols. Well, except spaces. x* works but * does not. I ended up using a...workaround. I made a composite image: the basis is * (which renders nothing) and for a composite, I chose the burning logo again and typed in x * which generated a flaming X and a flaming asterisk. The composite image you can move, so I adjusted it so the x is outside the image and resized to just get the *. Repeated the same with x ** for two asterisks.
    – VLAZ
    Nov 8, 2021 at 16:41
  • You inspired me to write this: meta.stackoverflow.com/posts/comments/878287?noredirect=1 Nov 8, 2021 at 21:08
  • Re "The "Not an answer" flag": Can you address link-only answers as well? Nov 9, 2021 at 2:47
  • @PeterMortensen included them with a link for more information.
    – VLAZ
    Nov 9, 2021 at 6:23

Not the answer you're looking for? Browse other questions tagged .