Skip to content
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

Merged
merged 1 commit into from
Apr 8, 2019
Merged

resolve complex types and workaround promise reject types #70

merged 1 commit into from
Apr 8, 2019

Conversation

ggere
Copy link
Contributor

@ggere ggere commented Apr 7, 2019

2 things here, let me know and I can split them.

  1. 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>

  2. 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,

  • Gord

Copy link
Owner

@englercj englercj left a 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.

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 {
Copy link
Owner

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.

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
Copy link
Owner

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.

{
this.name = name;
this.type = type;
this.parent = parent;
Copy link
Owner

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;
Copy link
Owner

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.

@ggere
Copy link
Contributor Author

ggere commented Apr 8, 2019

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.

@englercj englercj merged commit 1c5c10a into englercj:master Apr 8, 2019
@ggere ggere deleted the feature/complex-types branch April 9, 2019 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants