-
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
base: main
Are you sure you want to change the base?
Conversation
@@ -9,7 +9,7 @@ import { convertBlockEventToActiveDealDbEntry } from './utils.js' | |||
/** | |||
* @param {number} blockHeight | |||
* @param {Queryable} pgPool | |||
* @param {(method:string,params:object) => object} makeRpcRequest | |||
* @param {(method:string,params:any[]) => Promise<any>} makeRpcRequest |
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.
In the code we are validating the response from the RPC request with typebox, so there is no need to infer a type with the function makeRpcRequest
.
* @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.
@@ -38,10 +38,17 @@ const RpcRespone = Type.Object({ | |||
result: Type.Any() | |||
}) | |||
|
|||
const ChainHead = Type.Object({ | |||
Height: Type.Number(), | |||
Blocks: Type.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.
We are not really interested in Blocks or CIDs, but only the Height of the Chainhead. We could follow this up with a PR that adds explicit types for Blocks and Cids, but I believe it is low priority at this point.
To keep this already big PR reviewable, I set this to Any.
@@ -52,7 +53,7 @@ export async function getActorEvents (actorEventFilter, makeRpcRequest) { | |||
} | |||
// TODO: handle reverted events | |||
// https://github.com/filecoin-station/deal-observer/issues/22 | |||
const typedRawEventEntries = rawEvents.map((rawEvent) => Value.Parse(RawActorEvent, rawEvent)) | |||
const typedRawEventEntries = rawEvents.map((/** @type {any} */ rawEvent) => Value.Parse(RawActorEvent, rawEvent)) |
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.
rawEvents are parsed right after this point, so it is safe to use any.
@@ -7,7 +7,7 @@ import * as Sentry from '@sentry/node' | |||
* | |||
* @param {PgPool} pgPool | |||
* @param {number} batchSize | |||
* @param {(eligibleDeals: Array) => Promise<{ingested: number; skipped: number}>} submitDeals | |||
* @param {(eligibleDeals: Array<any>) => Promise<{ingested: number; skipped: number}>} submitDeals |
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 would suggest following up the explicit typing for eligible deals with another PR, as this would make the existing PR a lot bigger. WDYT?
@@ -45,7 +45,7 @@ export const findAndSubmitUnsubmittedDeals = async (pgPool, batchSize, submitDea | |||
* | |||
* @param {PgPool} pgPool | |||
* @param {number} batchSize | |||
* @returns {AsyncGenerator<Array>} | |||
* @returns {AsyncGenerator<Array<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.
Same as here.
@@ -82,7 +82,7 @@ const findUnsubmittedDeals = async function * (pgPool, batchSize) { | |||
* Mark deals as submitted. | |||
* | |||
* @param {Queryable} pgPool | |||
* @param {Array} eligibleDeals | |||
* @param {Array<any>} eligibleDeals |
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.
Same as here.
@@ -112,7 +112,7 @@ const markDealsAsSubmitted = async (pgPool, eligibleDeals) => { | |||
* | |||
* @param {string} sparkApiBaseURL | |||
* @param {string} sparkApiToken | |||
* @param {Array} deals | |||
* @param {Array<any>} deals |
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.
Same as here.
@@ -14,6 +18,7 @@ const decodeCborInBase64 = (data) => { | |||
*/ | |||
const rawEventEntriesToEvent = (rawEventEntries) => { | |||
// Each event is defined by a list of event entries which will parsed into a typed event | |||
/** @type {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.
We do not yet know the event type at this point, which is why I used any as a type declaration here.
…ub.com/filecoin-station/deal-observer into nhaimerl-activate-strict-type-checking
@NikolasHaimerl if you reword this to |
@@ -37,6 +38,10 @@ assert(finalityEpochs <= maxPastEpochs) | |||
const pgPool = await createPgPool() | |||
const { recordTelemetry } = createInflux(INFLUXDB_TOKEN) | |||
|
|||
/** | |||
* @param {(method:string,params:any[]) => Promise<any>} makeRpcRequest |
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 RPC call can return multiple different types of responses which are usually validated using TypeBox right after they return.
The parameters also differ in each request which is why the any type was used.
I suggest to let TS Wiz @bajtos handle this review 🙏 |
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.