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
{{ message }}
Repository navigation
Parens on union type fail for function arguments (JSDoc style) #25779
Ah, the problem is that the parameters to a closure-style function() type are parsed just like normal parameters, and parameters don't normally start with a parenthesis:
functionx(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.
As an aside, I'm hoping to get ESLint's valid-jsdoc rule working together with TypeScript's JSDoc support. Currently, the valid-jsdoc rule treat's TypeScript's inline imports as invalid types. I've proposed eslint/doctrine#216 to fix this. If anybody knows an ESLint contributor or wants to weigh in there, I'd appreciate it. (TypeScript's support for importing types feels like a pretty critical feature.)
Activity
mhegazy commentedon Jul 18, 2018
Nathan Shively-Sanders (@sandersn) would be nice to get this in to unblock the openlayers/openlayers PR
tschaub commentedon Jul 19, 2018
It looks like removing the parens from the union is not an easy alternative unless we remove our ESLint
valid-jsdocrule.That rule considers this a valid JSDoc comment:
And this is an error:
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.
sandersn commentedon Jul 19, 2018
Looks like you don't even need a union type to repro this:
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.
sandersn commentedon Jul 19, 2018
Ah, the problem is that the parameters to a closure-style
function()type are parsed just like normal parameters, and parameters don't normally start with a parenthesis: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.
sandersn commentedon Jul 19, 2018
Fix is up at #25799
mhegazy commentedon Jul 19, 2018
Tim Schaub (@tschaub) the fix should be in tomorrow's
typescript@next.tschaub commentedon Jul 19, 2018
Awesome. Thanks Nathan Shively-Sanders (@sandersn) and Mohamed Hegazy (@mhegazy). I'll test it out tomorrow.
As an aside, I'm hoping to get ESLint's
valid-jsdocrule working together with TypeScript's JSDoc support. Currently, thevalid-jsdocrule treat's TypeScript's inline imports as invalid types. I've proposed eslint/doctrine#216 to fix this. If anybody knows an ESLint contributor or wants to weigh in there, I'd appreciate it. (TypeScript's support for importing types feels like a pretty critical feature.)