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

chore(gatsby): migrate run-sift to TS #25055

Merged
merged 6 commits into from
Jun 17, 2020
Merged

chore(gatsby): migrate run-sift to TS #25055

merged 6 commits into from
Jun 17, 2020

Conversation

pvdz
Copy link
Contributor

@pvdz pvdz commented Jun 17, 2020

Converts run-sift to TS and removes "sift" from the file name.

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 17, 2020
@pvdz pvdz added topic: TypeScript migration and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jun 17, 2020
@pvdz pvdz marked this pull request as ready for review June 17, 2020 14:34
@pvdz pvdz requested a review from a team as a code owner June 17, 2020 14:34
Copy link
Contributor

@ascorbic ascorbic left a 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>,
Copy link
Contributor

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>

Copy link
Contributor Author

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?

Copy link
Contributor Author

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 :/

packages/gatsby/src/redux/run-fast-filters.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/run-fast-filters.ts Show resolved Hide resolved
packages/gatsby/src/redux/run-fast-filters.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/run-fast-filters.ts Outdated Show resolved Hide resolved
@pvdz
Copy link
Contributor Author

pvdz commented Jun 17, 2020

Typing fixed, tests are still broken.

@pvdz pvdz marked this pull request as draft June 17, 2020 15:05
pvdz added 6 commits June 17, 2020 17:09
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.
@pvdz
Copy link
Contributor Author

pvdz commented Jun 17, 2020

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 :)

@pvdz pvdz marked this pull request as ready for review June 17, 2020 15:25
@pvdz pvdz added the status: needs core review Currently awaiting review from Core team member label Jun 17, 2020
Copy link
Contributor

@blainekasten blainekasten left a 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!

@blainekasten blainekasten merged commit be27140 into master Jun 17, 2020
@delete-merged-branch delete-merged-branch bot deleted the run-sift-ts branch June 17, 2020 17:05
axe312ger pushed a commit that referenced this pull request Jun 23, 2020
* 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.
pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this pull request Apr 28, 2022
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs core review Currently awaiting review from Core team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants