-
Notifications
You must be signed in to change notification settings - Fork 42
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
resolve complex types and workaround promise reject types #70
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great change, thanks for doing this. I only have some nit-picky style things but looks good otherwise.
src/type_resolve_helpers.ts
Outdated
const rgxCommaAll = /,/g; | ||
const rgxParensAll = /\(|\)/g; | ||
|
||
const anyTypeNode = ts.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword); | ||
const strTypeNode = ts.createKeywordTypeNode(ts.SyntaxKind.StringKeyword); | ||
|
||
const anyGeneric: IGenericType = { kind: 'type', name: 'any', resolved: anyTypeNode }; | ||
const strGeneric: IGenericType = { kind: 'type', name: 'string', resolved: strTypeNode }; | ||
enum tsNodeTypes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Please use cap-first camel case with an E
prefix for enums. So ENodeType
.
src/type_resolve_helpers.ts
Outdated
UNION, // (a|b|c) has types for children | ||
FUNCTION, // function() has arguments for children | ||
TUPLE, // [a,b] has types for children | ||
TYPE // string, X has no children |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Always leave a trailing comma.
src/type_resolve_helpers.ts
Outdated
{ | ||
this.name = name; | ||
this.type = type; | ||
this.parent = parent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified by adding public
to the constructor args and removing the assignments here and the decls above. Similarly the = []
can be done in the children decl above.
++count; | ||
else if (parts[i] === closeBracket) | ||
if (--count === 0) | ||
return i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Use some braces here please, little too complex to not have them.
Updates based on your review and squashed them, hope that's okay. Thanks for the review. I might try to clean up the code a bit more in the future, but I'll do a new PR for that. I think I can remove the 2nd recursive pass and just do it in one. |
2 things here, let me know and I can split them.
Complex types like a union that had a generic, or a generic that had a union could not be resolved, ex: Promise<Array.<*>|Object|number|string>
We like to document our promise resolve and rejection types separated with a comma, ex: Promise<ResolveType, RejectType>. There doesn't seem to be consensus on exactly how do to this based on this still open feature request: Feature: Documenting Promises jsdoc/jsdoc#509. Typescript does not define the RejectType of a promise it is always 'any', see: Different types for rejected/fulfilled Promise microsoft/TypeScript#7588. Due to this I've added a workaround that removes the second type when parsing a Promise.
Thanks btw,