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

[DO NOT MERGE] Reproduce internal error in tsc #7

Draft
wants to merge 16 commits into
base: dev
Choose a base branch
from

Conversation

brodycj
Copy link
Owner

@brodycj brodycj commented Nov 1, 2019

This PR shares many commits in common with PR #6 for strict JSDoc type linting.

The following update in 032d29d causes tsc 3.6.4 to crash:

commit 032d29dd715a78e7a84567bfbefb63faf43cc939
Author: Christopher J. Brody <chris@brody.consulting>
Date:   Fri Nov 1 15:54:25 2019 -0400

    [TBD] add @typedef JSDoc comment to module.exports in lib/program-helper.js - tsc (version 3.6.4) seems to throw an internal error at this point

diff --git a/lib/program-helper.js b/lib/program-helper.js
index 4226780..619ffce 100644
--- a/lib/program-helper.js
+++ b/lib/program-helper.js
@@ -118,4 +118,7 @@ Helper.getOptions = function () {
     return commander;
 };
 
+/**
+ * @typedef {object} Helper
+ */
 module.exports = Helper;

This seems to be an interesting case of microsoft/TypeScript#32231.

I think there is more work I have to do to export the correct helper object type.

/cc @rbiggs

@brodycj brodycj self-assigned this Nov 1, 2019
@rbiggs
Copy link

rbiggs commented Nov 1, 2019

I think that's failing because you trying to type a complex object with properties as just Object. Object is very generic, equivalent to type any. But it's useful for building up type definitions for complex objects. When you use @typedef think of it as the same as TypeScript interface. Then use @prop to define properties on that object. After creating a type definition, you need to type the object using `/** @type {SomeType} */ right before the object you want to type.

I took the liberty to look at your Helper function. I think what you want is something like this:

/**
 * @typedef {Object} Helper
 * @prop {() => string} getTSCCommand
 * @prop {() => any[]} resolveTSFiles
 * @prop {() => Command} getOptions
 */

// Apply the above type to the Helper object:
/** @type {Helper} */
module.exports = Helper;

But I'm not sure is that's the best place to be designating Helper's type. Give it a try and let me know if it explodes.

@rbiggs
Copy link

rbiggs commented Nov 2, 2019

Ok, I downloaded this and took a good look at it. First main problem, TypeScript hates expando properties. You were create Helper as {} and then tacking methods on with dot notation. TypeScript cannot understand those. So I refactored you object which fixed that problem. Next I had a problem where you were importing the package.json. TypeScript needs a special flag for that so I added it to my tsconfig.json file. Oh, and I added a tsconfig.json file to organize all these TypeScript options. That means the npm script is just:

"scripts": {
   "checks": "tsc"
}

Here's a link to my repository: https://github.com/rbiggs/glob-tsc-dev

If you want. I can fork this, fix it and send you a pull request.

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