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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
style: Begin migration to TypeScript #888
Conversation
fa5159f
to
2047828
Compare
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.
One comment, otherwise LGTM 馃憤
* @template T | ||
* @param {string} fnName | ||
* @param {T} [opts] | ||
* @returns {T} |
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 update this or remove?
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.
Of course! What direction would you like to take?
I found this function is the hardest part. Here's how it is used in start and install:
selenium-standalone/lib/install.js
Lines 34 to 37 in 57e1eb1
async function install(_opts) { | |
const opts = checkArgs('Install API', _opts); | |
Given an optional _opts
, when we call checkArgs('...', _opts)
we want to return that type (or Partial). I got stuck here with the Partial<T>
:
/**
* @template T
* @param {string} fnName
* @param {T} opts
* @returns {Partial<T>}
*/
const checkArgs = (fnName, opts = {}) => {
// ^^^^^^^^^
// Type '{}' is not assignable to type 'T'.
// 'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.ts(2322)
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.
oh .. not sure how to do that with JSDoc, in TS this would look like:
const checkArgs<T extends object> = (fnName: string, opts: T = {}): T => {
debug(fnName + ' called with', opts);
return { ...opts };
};
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.
Yea, I wanted to work in JS so I could work in smaller steps. Would you be OK with the change knowing that it only changes what is logged in the debug
call from {}
to undefined
? I added tests before I gave up on JSDoc. 馃槅
--
I following microsoft/TypeScript#41768 which says that:
<T extends object>
would become
* @template {object} T
but TS infers it as unknown
:
/**
* @template {object} T
* @param {string} fnName
* @param {T} [opts]
* @returns {T}
*/
const checkArgs = (fnName, opts = {}) => {
// ^^^^^^^^^
// Type '{}' is not assignable to type 'T'.
// '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.ts(2322)
It is similar with @template {object} T
but you get {}
instead of unknown
:
Type '{}' is not assignable to type 'T'.
'{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.ts(2322)
That's where I gave up, added a test, and removed = {}
. We could also inline the method to remove the problem.
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.
Yeah, this should not blocking us from moving forward.
Proposed Changes
nyc
to check code coverage (to see what I can change with confidence)"build"
script that can fail in the pipelineNotes
Next Steps
_handle
not being defined. I'm not sure what to replace that with. 馃し