-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
chore(gatsby): migrate run-sift to TS #25055
Conversation
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.
Great to see this going in! Just a few nits, and a general comment that it's easier to read function declarations if the argument type is declared as an interface or type, rather than inline
@@ -50,7 +50,7 @@ export function createDbQueriesFromObject(filter: object): Array<DbQuery> { | |||
} | |||
|
|||
function createDbQueriesFromObjectNested( | |||
filter: object, | |||
filter: Record<string, any>, |
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 this be Record<string, unknown>
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.
Changing the any
to unknown
triggers cascading errors. Are you sure that's the right way?
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.
May be related to this:
packages/gatsby/src/db/common/query.ts:63:57 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'Record<string, unknown>'.
I hate that my editor throws different errors from yarn typecheck
from whatever yarn format
does. There should be one state :/
Typing fixed, tests are still broken. |
This change is broken because references are not updated. Separate commit for your reviewing pleasure. (The PR will squash it and github will still screw up the rename but at least review is good.)
While trying to be type correct, coercing the value to string has the unintended side effect of allowing regexes (or any other type) as $regex arg. So instead now throwing an explciit error for that case. Also reverted the type where it returns an Array. Apparently there are cases where it is not an array.
Ok. Tests should pass now. Typings were cleaned up. I thought runFastFilters would accept an array of filters to apply. But apparently, and through the magic of lodash, that's not exactly the case. So I reverted annotating those input/output types as arrays. Also removed a String case that was accidentally allowing types that shouldn't be allowed. Good thing we have tests :) |
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.
Really great stuff Peter! This code is by no means easy to type. Glad to see you tackle it well!
* Rename file to .ts and drop the sift name This change is broken because references are not updated. Separate commit for your reviewing pleasure. (The PR will squash it and github will still screw up the rename but at least review is good.) * Convert run-fast-filters (run-sift) to TS * Applied suggestions * Remove more unknowns * wip * Fix regression While trying to be type correct, coercing the value to string has the unintended side effect of allowing regexes (or any other type) as $regex arg. So instead now throwing an explciit error for that case. Also reverted the type where it returns an Array. Apparently there are cases where it is not an array.
Converts run-sift to TS and removes "sift" from the file name.