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 codeaxios
.
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 javascript graph-theory only in, say, c# 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
(axios as jest.Mocked<typeof axios>)
twice. The direct JS equivalent is literally the codeaxios
. 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.