Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We have
typeof BasePlugin
but alsoBasePlugin
? Should be perhaps beInstanceOf<typeof BasePlugin>
?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.
I'm not familiar with the nuances of that, I'd need to look it up. But basically what we were missing was that the user can either pass the plugin class, or a plugin instance. Can
InstanceOf<>
target both at once?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.
Theoretically I think it would satisfy both, but technically it means the initialized instance. Regardless, if we want to type the instance, there should at least be a
InstanceOf
type.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.
BasePlugin
would target an instance ofBasePlugin
(or any other subclass ofBasePlugin
), why do we need theInstanceOf
?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.
Cannot find name 'InstanceOf'
, also it doesn't seem to exist, or what am I missing?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 we try to replace both with this? I think it should be stricter than current attempt
https://www.typescriptlang.org/docs/handbook/utility-types.html#instancetypetype
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.
The docs says that
InstanceType<typeof C>
isC
though, what's stricter about it? I just tried in the playground, and it seemsInstanceType
doesn't help us here: https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC0G8BQ1oA9oF5oAYDcK0AnlrgQL4pIAuRADgKbQAqOpAkgHYTVifANm9BgB5ajAPYAzOAD4C4pswCMpWAuEsATGugAfaIulwCSZMAndqhhjxwAuFm2ycGAdzhILVmz2WPWNSRKM0JUbx5fagcWVRd3Twjraltqf1igkORUcMtIlLsAnVJXD1gvPOTU9OYdbHKQpCAThere 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.
Thanks for checking. I remembered this helped me with typing tus-node-server, perhaps I remember wrong. This is okay then!
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.
That being said,https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC0G8BQ1oA9oF5oAYDcK0AnlrgQL5JKiQwAi0ApmgC6MB2AJjPApdeCjQAookKoM2AIwFUqEtgDMFFEhZEADo2gAVHKXVaA9gDM40AD7RDjU9DprN2nVINO7sAjd0AmN8bM6AiRkYCN2CBZrRkicAC5dfWxYanDI6MipBL1SBzCIqLZIn2ykkSR+ZDlofPSilnjdV2TUgoyWLKbc1rqYlhLE0mEKqiq5WsK+xp0-bon2zpnSFPn6gZzsYf4kIAtypeof
doesn't seem to behave as we are trying to make it behave:EDIT: turns out TS applies the "if it walk like a duck and quack like a duck, …" principle, so the above is expected.