plantain-00 / type-coverage

A CLI tool to check type coverage for typescript code
MIT License
1.2k stars 43 forks source link

Add support for `namespace` #128

Closed Raynos closed 10 months ago

Raynos commented 10 months ago

Version(if relevant): 1.0.0

Environment(if relevant):

I've had to add type-coverage ignore to everything coming out of our typescript namespace.

Code(if relevant):

type Payload = z.infer<
  typeof Schemas.AsyncJobQueueMessage.transactionSideEffects
>;

Expected:

Expected it not say tranasactionSideEffects is any ; but it does

See namespace definition

export namespace AsyncJobQueueMessage {
  export const actionIngressMessage = z.object({
    idempotencyKey: z.string().nullish(),
    version: z.literal('ACTION_SCHEMA_V1'),
    action: z.object({
      id: z.string(),
      occurredAt: z.preprocess(arg => {
        if (typeof arg == 'string' || arg instanceof Date) return new Date(arg);
        return null;
      }, z.date()),
    }),
    payload: z.discriminatedUnion('type', [
      z.object({
        type: z.literal(ActionType.USER_PURCHASED_NFT),
        collectionType: z
          .nativeEnum(ActivityFeedGroupPurchaseCollectionType)
          .optional(),
        collector: z.object({
          id: z.string(),
        }),
        release: z.object({
          id: z.string(),
        }),
      }),
      z.object({
        type: z.literal(ActionType.ADDED_RELEASE_TO_SHELF),
        user: z.object({
          id: z.string(),
        }),
        shelf: z.object({
          id: z.string(),
          isNewShelf: z.boolean(),
        }),
      }),
      z.object({
        type: z.literal(ActionType.USER_ADDED_RELEASE),
        user: z.object({
          id: z.string(),
        }),
        release: z.object({
          id: z.string(),
        }),
      }),
      z.object({
        type: z.literal(ActionType.USER_LIKED_RELEASE),
        user: z.object({
          id: z.string(),
        }),
        release: z.object({
          id: z.string(),
        }),
        shelf: z.object({
          id: z.string(),
        }),
      }),
      z.object({
        type: z.literal(ActionType.USER_LIKED_SHELF),
        user: z.object({
          id: z.string(),
        }),
        shelf: z.object({
          id: z.string(),
        }),
      }),
    ]),
  });

  export const actionFanoutMessage = actionIngressMessage.extend({
    activityFeed: z.object({
      id: z.string(),
    }),
  });

  export const audioTranscodeMessage = z.object({
    version: z.literal('AUDIO_TRANSCODE_SCHEMA_V1'),
    mediaItem: z.object({
      associationType: z.string(),
      associationId: z.string(),
      mediaType: z.string(),
    }),
    replaceExisting: z.boolean().optional(),
  });

  export const audioFingerprintingUploadAcrCloudMessage = z.object({
    method: z.literal('audioFingerprinting-upload-AcrCloud'),
    track: z.object({
      mediaSource: z.object({
        bucket: z.string(),
        key: z.string(),
      }),
      id: z.string(),
      releaseId: z.string(),
    }),
  });

  ....

  export const transactionSideEffects = z.object({
    method: z.literal('processTransactionSideEffects'),
    artistId: z.string(),
    artistUserId: z.string(),
    collectorsAddresses: z.array(z.string()),
    collectorUserIds: z.array(z.string()),
    releaseId: z.string(),
    nftIds: z.array(z.string()),
    uniqueKey: z.string(),
  });

  ...
Raynos commented 10 months ago

This was not the issue, the issue was that this z.object() generic thinger contains an any :(