-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Search Terms
set function declaration type
Suggestion
To define a function type, we currently have to use function expressions:
type Fun<T> = (value: T) => T
export let foo: Fun<number> = function (value) {
return value
}My suggestion is to make that possible for function declarations as well:
export function foo: Fun<number> (value) {
return value
}Use Cases
As a superset of JavaScript, TypeScript shouldn't enforce us to change the actual runtime logic in order to apply types. In this case, you're forced to use a function expression when a function declaration is fine.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
awerlogus
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created