-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Design issue - Function typing inconsistency (?) #18749
Comments
The arrow syntax there is just a shorthand. The only observable differences have to do with |
Well Ryan, you could work in politics or marketing with the spin you've put on that !! :) - this.... including calls to I was hoping someone would either a) advise the documentation was incorrect and provide the correct documentation, The arrow syntax has a specific meaning in JS and as TS is a super set of JS the arrow syntax should have the same meaning in TS and not be a shorthand for something else. The syntax given is analogous to having a LanguageX to C++ Transpiler and saying that you can write
and the compiler will see 2.6 is a float and replace |
We designed the type syntax ( You've applied your own interpretation of this syntax ( I can assume that |
Ok, so the answer to my original question is ; "The arrow syntax existed in its current form in TS before it was introduced to JS (with its new connotations) <and we are | but we are not> going to change it to mirror the JS standard. For now, in the context of specifying a type, arrow syntax can be considered as a super type from which the JS arrow function type and JS 'function' function type are independently descended. There is currently no way to specify a type specific to either type of JS function." As to applying my own interpretation, the site says "TypeScript starts from the same syntax and semantics that millions of JavaScript developers know today", which syntax and semantics gives my interpretation to the syntax in question. There is no specific mention that some JS syntax has a different meaning in TS specific contexts which is the case here. So, for someone new to TS, my interpretation was at the very least, reasonable. As to your void* example, of course you would be wrong to 'assume that void* x = 0; in C means "Please allocate an int and give me a pointer to it"' - it means "allocate space to store an address and store the value 0 in it". This is how a typed variable declaration and assignment is interpreted and implemented which is in keeping with my original interpretation of your syntax ;
being "allocate space for an arrow function and store a "function" function there" which raises the obvious questions unless you are aware of the relevant history and associated peculiarity when the correct interpretation becomes ; "allocate space for a JS function of any kind and store a "function" function there" which is fine. What you quite rightly suggest as invalid behaviour is, in the absence of more information, exactly how the syntax appears to be implemented - i.e. It does allocate a "function" function and give you a 'pointer' to it ! - This is what caused me to question it. I can see a whole lot of confusion and no doubt some subtle this related bug biting someone on the arse at some point. I presume (as a Humpty fan) that you're paying your arrow syntax extra since ES2015. |
No. Arrow functions were in ES Committee at the same time as they were introduced in TypeScript. It is 100%, actually on purpose, for real we thought about it, that the type syntax
It's not clear to me why you would want to, except for the case of
This cannot possibly be surprising. On a practical level, rigorously enforcing a distinction between regular and arrow function expressions would be counterproductive. Other than
Which is why we added |
I tried posting at
<!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->
but doesn't look like anyone is reading issues posted over there....
So copy of original post ;
From the Typescript web site ( https://www.typescriptlang.org/docs/handbook/functions.html ) ;
....but an arrow function is not functionally the same as a "function" function - they are not the same (type of) thing ( even if somewhere one is a super class of the other ).
The text was updated successfully, but these errors were encountered: