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

Expose types #5

Merged
merged 2 commits into from
Mar 29, 2019
Merged

Expose types #5

merged 2 commits into from
Mar 29, 2019

Conversation

jkrems
Copy link
Collaborator

@jkrems jkrems commented Mar 28, 2019

This allows users of nilo to get the proper autocomplete etc..

@@ -22,6 +26,9 @@ function toNumber(value) {
* @param {Options} options
*/
async function start(ctx, options) {
await ctx.initialize();
await ctx.configure();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were mostly added so that we "document" the public interface. E.g. my initial typings were missing these methods and I wanted to make sure that would be caught.

@@ -254,7 +245,11 @@ class Scope {
* @returns {Injector}
*/
createInjector(init, parent) {
return new Injector(this, init, parent);
return new Injector(
/** @type {import('../typedefs').Scope} */ (this),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you preceded class Scope { with /** @type {typeof import('../typedefs').Scope} */ would that make it so you didn't have to cast all these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find a way around this. Tried different variations but inside of the class body those two are considered different types. :( There may be some magical combination of interfaces and factory functions that would make this work but it would make the code a bit harder to follow.

lib/nilo.js Outdated
exports.App = /** @type {typeof import('./typedefs').App} */ (require('./app'));
exports.Project = /** @type {typeof import('./typedefs').Project} */ (require('./project'));
exports.Registry = /** @type {typeof import('./typedefs').Registry} */ (require('./registry'));
exports.main = /** @type {typeof import('./typedefs').main} */ (require('./main'));
Copy link
Member

@dbushong dbushong Mar 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if these files imported their types from typedefs in their export location, would that be possible/cleaner?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! And I think it makes everything look a bit nicer. Good idea!

@jkrems jkrems merged commit bab7df7 into master Mar 29, 2019
@jkrems jkrems deleted the jkrems/feature/master/types branch March 29, 2019 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants