-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type Cast or Assertions on the FunctionDeclaration #40378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
My proposed syntax for this is as follows: // Given some type:
type F = <T>(param: T) => string;
// New syntax for casting:
function foo1(param) { /* ... */ } as F
<F>function foo2(param) { /* ... */ }
// New syntax for declarations:
function foo3: F (param) { /* ... */ }
declare function foo4: F; Note: declare const foo4: F; // <-- Cannot redeclare block-scoped variable 'foo4'. ts(2451)
declare namespace foo4 { /* ... */ } |
Is this a duplicate of #22063? I'm wondering if we can consolidate these these issues to focus attention on them. I would love to see the ability to type function declarations, no matter what syntax is ultimately chosen. |
Yes I guess? |
implemented by #57859, but since it has been closed, I believe this idea is no longer considered by the ts team |
Search Terms
function declaration type cast assertions
Suggestion
A new syntax to cast or assert function declaration as a type T.
Use Cases
In some cases, we want to type-check a function to obey a type constraint but it is not easy to do on the FunctionDeclaration statement.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: