Hello everyone
I have send a pull request to add a return type for TypeScript function snippet: #39133
{
"Function Statement": {
"prefix": "function",
"body": [
- "function ${1:name}(${2:params}:${3:type}) {",
+ "function ${1:name}(${2:params}:${3:type}): ${4:return} {",
"\t$0",
"}"
],
"description": "Function Statement"
}
}
Because I think it should be a best practice for the TypeScript that to always specify the function return type.
When you define a function, you should able to know what type you want to return. If you return other type, the compiler will tell you there is maybe a mistake:

So I think we should always specify the function return type.
But @mjbvz think TypeScript can correctly infer the return type in the majority of cases and some users would end up deleting the return type in the snippet.
Please give your comments. Thanks.
Hello everyone
I have send a pull request to add a return type for TypeScript function snippet: #39133
{ "Function Statement": { "prefix": "function", "body": [ - "function ${1:name}(${2:params}:${3:type}) {", + "function ${1:name}(${2:params}:${3:type}): ${4:return} {", "\t$0", "}" ], "description": "Function Statement" } }Because I think it should be a best practice for the TypeScript that to always specify the function return type.
When you define a function, you should able to know what type you want to return. If you return other type, the compiler will tell you there is maybe a mistake:
So I think we should always specify the function return type.
But @mjbvz think TypeScript can correctly infer the return type in the majority of cases and some users would end up deleting the return type in the snippet.
Please give your comments. Thanks.