Skip to content

How about add a function return type for TypeScript snippet? #39231

@Heatwave

Description

@Heatwave

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:

image

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.

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityjavascriptJavaScript support issuessnippets

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions