-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Parens on union type fail for function arguments (JSDoc style) #25779
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
@sandersn would be nice to get this in to unblock the openlayers/openlayers PR |
It looks like removing the parens from the union is not an easy alternative unless we remove our ESLint That rule considers this a valid JSDoc comment: /**
* @param {function((string|boolean)): boolean} bar A function.
* @returns {boolean} True.
*/
foo(bar) {
return true;
} And this is an error: /**
* @param {function(string|boolean): boolean} bar A function.
* @returns {boolean} True.
*/
foo(bar) {
return true;
} The lack of a JSDoc spec makes it tough to say which one is "correct" - but the Closure Compiler docs have a sensible suggestion for type unions:
I'll dig around to see if I can find where a fix might be applied. Any pointers are appreciated. |
Looks like you don't even need a union type to repro this: /** @type {function((string)): string} */
var x = s => s.toString() I'm looking at this. It might be easy to fix, as long as the parser isn't getting confused when trying to speculatively parse an arrow function type. |
Ah, the problem is that the parameters to a closure-style function x(a, (b), c) { } // parse error at '(b)' We have exceptions in the parser when parsing parameters of a jsdoc function type, but they don't apply at this parameter-start location. I think I can fix it by explicitly special-casing the parameter list of jsdoc functions. |
Fix is up at #25799 |
@tschaub the fix should be in tomorrow's |
Awesome. Thanks @sandersn and @mhegazy. I'll test it out tomorrow. As an aside, I'm hoping to get ESLint's |
TypeScript Version: [email protected]
Search Terms: function arguments grouped union type
Code
I notice that if a union type is grouped with
(
and)
it works as a return type but not as an argument type. For example, this does not work:While this does work:
Expected behavior:
With this
tsconfig.json
:I expected
tsc
to succeed.Actual behavior:
Perhaps this is a known limitation. I can remove the parens. But I thought it might also be a parsing bug.
The text was updated successfully, but these errors were encountered: