-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Introduce compact callback declaration #14173
Comments
The problem is we already have loosely typed function declaration like |
Yes, but on the other hand we can have this rule kicks in only if the I think that is still doable. |
This rule is too sloppy, consider: (str, number) => string The first one is not a type, but the second one is. How to resolve this signature? Also, this requires resolving new parser conflict (Gen<A, B>) => string Cannot be determined to be a syntax error or not. Another confusion: type A = ({a: string, b: number}) => string // or ([string, number]) => string
var A = ({a: string, b: number}) => string // ([string, number]) => string has totally different meaning. |
Would stay this won't apply.
is a valid type, because you are doing a type declaration.
this would be an implementation. One thing TypeScript good at is a clear separation of type definition and implementation, because the implementation side is just JavaScript. Of course, there could be still confusing cases. |
Not sure what do you mean here. If this proposal is accepted and implement, would it be considered correct syntax? e.g. |
is a syntax error now. If the proposal is accepted, this is no longer a syntax error. Error handling in parser requires rewriting (this impacts transpiling). Another problem: we don't have types for spread arguments: (a, ...b: any[]) => void |
|
Now consider: merging all rules mentioned above into one rule to parse and check function type (Especially, pay attention to how errors should be reported. For example, how generic argument type error is reported as I pointed above). The final rule will quickly explode when new syntax is introduced. Also, as a proposal, keep an eye on breaking change. I found myself perplexed when writing it out. It probably means users will be confused too. |
Yes, that may need to change, but also may not. It depends on when the arbitrary argument is injected. When |
Actually there is only two:
Then parse as normal. |
When? You have to know
If it isn't, should |
If |
No, you cannot. To resolve type information, you need to have AST because TSC is syntax driven. To have AST, you have to parse. To parse you have to know if The rule you listed is not sufficient, if without specifying how type information is integrated in parsing. |
I see. I'm mentally handicap when talking about AST, so I trust your judgement. 😛 In the SO post it mentioned Haskell. Can some idea be drawn from that? Or it is a radical change? Would it be possible that when tsc parses One key is this rule only applies during type declaration, i.e. |
Of course. And Haskell does not support untyped function type
I don't know whether it is possible without parsing conflict before thorough mulling. It requires a proposer to bring out a viable algorithm. But before that, think about the ROI of this feature again. It brings many breaking changes. Yet we can still do something like below type FN0<R> = () => R
type FN1<T1, R> = (t: T) => R
type FN2<T1, T2, R> = (t1: T1, t2: T2) => R
// ..... |
The requirement to give names to symbols that you will never subsequently use is one of TypeScript's biggest syntactic warts. I think it's worth rectifying even at the expense of breaking changes. |
As noted by @HerringtonDarkholme, this would be a breaking change. |
tsc: 2.1.6
Originally from: http://stackoverflow.com/posts/42322317
I can see that needing to declare the argument name in the callback function type could be redundant, and MAY BE make even less sense in higher order function.
So maybe it is beneficial to support this shorten form
arrayCompare(f: (Ord) => (Ord) => boolean)
?Do you see other application?
One drawback it that the compiler need to add arbitrary names to make completion consistent:
The text was updated successfully, but these errors were encountered: