You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently functions can only typed via a type alias when they are an expression, function declarations can't be typed this way.
Could typing function declarations via type alias be supported?
Use Cases
Declaring a function's type via a type alias.
Examples
In a declaration file
typeF=<T>(param: T)=>string;// New Syntax
declare functionfoo: F;declarenamespacefoo{/* ... */}
declare const foo: F; doesn't work in the above example as it results in "Cannot redeclare block-scoped variable 'foo'. ts(2451)"
In a standard TypeScript file
typeF=<T>(param: T)=>string;// New Syntax: Castingfunctionbar1(param){/* ... */}asF<F>functionbar2(param){/* ... */}// New Syntax: Declaringfunctionbar3: F(param){/* ... */}
Search Terms
"function declaration" "type alias"
Suggestion
Currently functions can only typed via a type alias when they are an expression, function declarations can't be typed this way.
Could typing function declarations via type alias be supported?
Use Cases
Declaring a function's type via a type alias.
Examples
In a declaration file
declare const foo: F;
doesn't work in the above example as it results in "Cannot redeclare block-scoped variable 'foo'. ts(2451)"In a standard TypeScript file
Playground
https://www.typescriptlang.org/play?#code/C4TwDgpgBAYlC8UA8AVAfACjAQwE7YFsAuKFASgTSgDcB7ASwBMBuAKFYGNaA7AZ2CjAAFvV4B1WrgDWvEnERY8hCvCoBvKAHoAVFAB0BqNs1QAvm1aMIHADZ5oAMwCu3DsHo8oD2rTkWrtvZQ3IQQvDgcjj5QGjr6hsZm7M6u7p4ARngAjIr4BBSxugZ6RiamUNi8sOxIMGgpbh7cUJm4AEy5yjFaRQllyS6NGXgAzHJQnfndccWlZkA
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: