-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
backend/lib/deal-observer.js
Outdated
* @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) => { |
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 deal is validated shortly after this call using typebox. This means that it is safe to use any 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.
@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.
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.
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.)
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 am introducing UnknownRow
type that we can share. I am happy to discuss a better name for this 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.
Ah, you can do pgPool.query<UnknownRow>(...)
in TypeScript, but that's unfortunately not possible with JSDoc-style typings :(
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.
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
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.
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({ |
unkown
types.
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.
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
👍🏻
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.
@bajtos can we disallow any
in typescript settings?
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.
@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:
…ub.com/filecoin-station/deal-observer into nhaimerl-activate-strict-type-checking
@NikolasHaimerl if you reword this to |
I suggest to let TS Wiz @bajtos handle this review 🙏 |
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 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.
Great work, @NikolasHaimerl! |
backend/bin/deal-observer-backend.js
Outdated
@@ -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' */ |
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 think you forgot to push the file '../lib/typings.js', no?
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.
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.
@bajtos Thanks for the review! After merging this branch and updating it with
Let me know if you have any thoughts! 🚀 |
Signed-off-by: Miroslav Bajtoš <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
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 made few more tweaks, the new version looks great now.
@juliangruber would you like to take another look as well?
Co-authored-by: Miroslav Bajtoš <[email protected]>
Co-authored-by: Julian Gruber <[email protected]>
Co-authored-by: Julian Gruber <[email protected]>
This PR proposes the following changes:
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.