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: enable strict type checking #80

Merged
merged 34 commits into from
Feb 24, 2025

Conversation

NikolasHaimerl
Copy link
Contributor

@NikolasHaimerl NikolasHaimerl commented Feb 4, 2025

This PR proposes the following changes:

  1. Enable strict type checking on the deal observer repository

Closes #51 .

The proposed solution enables strict type checking for the entire repository.
Wherever possible explicit types are used. In some cases the any time was used and I commented on my reasoning for doing so in this PR.

* @returns {Promise<Array<Static <typeof ActiveDealDbEntry>>>}
*/
export async function loadDeals (pgPool, query, args = []) {
const result = (await pgPool.query(query, args)).rows.map(deal => {
const result = (await pgPool.query(query, args)).rows.map((/** @type {any} */ deal) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deal is validated shortly after this call using typebox. This means that it is safe to use any type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos what do you think about introducing a new type, called ToBeParsed or similar, which equals any? This way we don't have any any, and can forbid it, but at the same time, signal that this type needs to be parsed, and will be parsed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Record<string, unknown>. I wish node-postgres was using that type for result.rows out of the box. (I'll handle this myself and push a new commit.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am introducing UnknownRow type that we can share. I am happy to discuss a better name for this type.

Copy link
Member

@bajtos bajtos Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you can do pgPool.query<UnknownRow>(...) in TypeScript, but that's unfortunately not possible with JSDoc-style typings :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversation is resolved as far as I am concerned. I propose to start a new thread if you disagree with some of the decisions I made in 7fab2e9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversation is resolved as far as I am concerned. I propose to start a new thread if you disagree with some of the decisions I made in 7fab2e9

After merging with main, we now can use SubmittableDeals

const SubmittableDeal = Type.Object({
, which I believe is a better alternative to unkown types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversation is resolved as far as I am concerned. I propose to start a new thread if you disagree with some of the decisions I made in 7fab2e9

After merging with main, we now can use SubmittableDeals

const SubmittableDeal = Type.Object({

, which I believe is a better alternative to unkown types.

I agree it's a better alternative than unknown 👍🏻

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos can we disallow any in typescript settings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos can we disallow any in typescript settings?

Not as far as I know.

There is a typescript-eslint rule no-explicit-any, but IIRC, typescript-eslint does not work with JSDoc-in-JS-files, plus we are using standard.js.

I am going to mention this topic here:

@NikolasHaimerl NikolasHaimerl marked this pull request as ready for review February 4, 2025 10:59
@NikolasHaimerl NikolasHaimerl requested review from juliangruber and bajtos and removed request for bajtos February 4, 2025 11:00
@juliangruber
Copy link
Member

See #51.

@NikolasHaimerl if you reword this to Closes #51, then GitHub will close the issue when this PR gets merged.

@juliangruber
Copy link
Member

I suggest to let TS Wiz @bajtos handle this review 🙏

@juliangruber juliangruber removed their request for review February 5, 2025 15:18
@NikolasHaimerl NikolasHaimerl mentioned this pull request Feb 7, 2025
58 tasks
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request goes in the right direction. I left some comments above pointing out places needing another look or more discussion.

You also need to merge in the latest main branch.

@bajtos
Copy link
Member

bajtos commented Feb 21, 2025

Great work, @NikolasHaimerl!

@@ -13,7 +13,7 @@ import { findAndSubmitUnsubmittedDeals, submitDealsToSparkApi } from '../lib/spa
import { getDealPayloadCid } from '../lib/piece-indexer-service.js'

/** @import {Queryable} from '@filecoin-station/deal-observer-db' */
/** @import {MakeRpcRequest} from '../lib/typings.js' */
/** @import {MakeRpcRequest, GetDealPayloadCid} from '../lib/typings.js' */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to push the file '../lib/typings.js', no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry for that!

I added my version of the typings file in 4cc2e50, but now I need to fix tsc errors that I did not expect.

@NikolasHaimerl
Copy link
Contributor Author

@bajtos Thanks for the review!

After merging this branch and updating it with main, a few things have changed:

  1. Instead of relying on unknown types for eligible deals, we can now use Submittable deals: Reference.
  2. In your commit, I noticed that the typings.js file was missing. I added a typings.d.ts file, following the approach you used in this change.
  3. I removed instances of the any type where possible and used unknown when no better alternative was available.

Let me know if you have any thoughts! 🚀

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made few more tweaks, the new version looks great now.

@juliangruber would you like to take another look as well?

@NikolasHaimerl NikolasHaimerl enabled auto-merge (squash) February 24, 2025 07:46
@NikolasHaimerl NikolasHaimerl merged commit c367281 into main Feb 24, 2025
8 checks passed
@NikolasHaimerl NikolasHaimerl deleted the nhaimerl-activate-strict-type-checking branch February 24, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable strict TypeScript checks
3 participants