-
Notifications
You must be signed in to change notification settings - Fork 2
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
Expose types #5
Conversation
bead594
to
9383ded
Compare
@@ -22,6 +26,9 @@ function toNumber(value) { | |||
* @param {Options} options | |||
*/ | |||
async function start(ctx, options) { | |||
await ctx.initialize(); | |||
await ctx.configure(); |
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.
?
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.
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), |
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.
if you preceded class Scope {
with /** @type {typeof import('../typedefs').Scope} */
would that make it so you didn't have to cast all these?
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.
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')); |
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.
if these files imported their types from typedefs in their export location, would that be possible/cleaner?
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.
Yep! And I think it makes everything look a bit nicer. Good idea!
This allows users of
nilo
to get the proper autocomplete etc..