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

Various TypeScript compilation errors, upgrading from 7.21.0 to 7.24.1 #436

Closed
bcoe opened this issue Feb 4, 2021 · 13 comments
Closed

Various TypeScript compilation errors, upgrading from 7.21.0 to 7.24.1 #436

bcoe opened this issue Feb 4, 2021 · 13 comments
Labels
Type: Bug Something isn't working as documented, or is being fixed
Projects

Comments

@bcoe
Copy link

bcoe commented Feb 4, 2021

What happened?

When upgrading from 7.21.0 to 7.24.1, I receive quite a few compilation errors:

node_modules/@octokit/webhooks/dist-types/generated/get-webhook-payload-type-from-event.d.ts:1:5037 - error TS2307: Cannot find module '@octokit/webhooks-definitions/schema' or its corresponding type declarations.

1 import { CheckRunEvent, CheckRunCompletedEvent, CheckRunCreatedEvent, CheckRunRequestedActionEvent, CheckRunRerequestedEvent, CheckSuiteEvent, CheckSuiteCompletedEvent, CheckSuiteRequestedEvent, CheckSuiteRerequestedEvent, CodeScanningAlertEvent, CodeScanningAlertAppearedInBranchEvent, CodeScanningAlertClosedByUserEvent, CodeScanningAlertCreatedEvent, CodeScanningAlertFixedEvent, CodeScanningAlertReopenedEvent, CodeScanningAlertReopenedByUserEvent, CommitCommentEvent, CommitCommentCreatedEvent, ContentReferenceEvent, ContentReferenceCreatedEvent, CreateEvent, DeleteEvent, DeployKeyEvent, DeployKeyCreatedEvent, DeployKeyDeletedEvent, DeploymentEvent, DeploymentCreatedEvent, DeploymentStatusEvent, DeploymentStatusCreatedEvent, ForkEvent, GithubAppAuthorizationEvent, GithubAppAuthorizationRevokedEvent, GollumEvent, InstallationEvent, InstallationCreatedEvent, InstallationDeletedEvent, InstallationNewPermissionsAcceptedEvent, InstallationSuspendEvent, InstallationUnsuspendEvent, InstallationRepositoriesEvent, InstallationRepositoriesAddedEvent, InstallationRepositoriesRemovedEvent, IssueCommentEvent, IssueCommentCreatedEvent, IssueCommentDeletedEvent, IssueCommentEditedEvent, IssuesEvent, IssuesAssignedEvent, IssuesClosedEvent, IssuesDeletedEvent, IssuesDemilestonedEvent, IssuesEditedEvent, IssuesLabeledEvent, IssuesLockedEvent, IssuesMilestonedEvent, IssuesOpenedEvent, IssuesPinnedEvent, IssuesReopenedEvent, IssuesTransferredEvent, IssuesUnassignedEvent, IssuesUnlabeledEvent, IssuesUnlockedEvent, IssuesUnpinnedEvent, LabelEvent, LabelCreatedEvent, LabelDeletedEvent, LabelEditedEvent, MarketplacePurchaseEvent, MarketplacePurchaseCancelledEvent, MarketplacePurchaseChangedEvent, MarketplacePurchasePendingChangeEvent, MarketplacePurchasePendingChangeCancelledEvent, MarketplacePurchasePurchasedEvent, MemberEvent, MemberAddedEvent, MemberEditedEvent, MemberRemovedEvent, MembershipEvent, MembershipAddedEvent, MembershipRemovedEvent, MetaEvent, MetaDeletedEvent, MilestoneEvent, MilestoneClosedEvent, MilestoneCreatedEvent, MilestoneDeletedEvent, MilestoneEditedEvent, MilestoneOpenedEvent, OrgBlockEvent, OrgBlockBlockedEvent, OrgBlockUnblockedEvent, OrganizationEvent, OrganizationDeletedEvent, OrganizationMemberAddedEvent, OrganizationMemberInvitedEvent, OrganizationMemberRemovedEvent, OrganizationRenamedEvent, PackageEvent, PackagePublishedEvent, PackageUpdatedEvent, PageBuildEvent, PingEvent, ProjectEvent, ProjectClosedEvent, ProjectCreatedEvent, ProjectDeletedEvent, ProjectEditedEvent, ProjectReopenedEvent, ProjectCardEvent, ProjectCardConvertedEvent, ProjectCardCreatedEvent, ProjectCardDeletedEvent, ProjectCardEditedEvent, ProjectCardMovedEvent, ProjectColumnEvent, ProjectColumnCreatedEvent, ProjectColumnDeletedEvent, ProjectColumnEditedEvent, ProjectColumnMovedEvent, PublicEvent, PullRequestEvent, PullRequestAssignedEvent, PullRequestAutoMergeDisabledEvent, PullRequestAutoMergeEnabledEvent, PullRequestClosedEvent, PullRequestConvertedToDraftEvent, PullRequestEditedEvent, PullRequestLabeledEvent, PullRequestLockedEvent, PullRequestOpenedEvent, PullRequestReadyForReviewEvent, PullRequestReopenedEvent, PullRequestReviewRequestRemovedEvent, PullRequestReviewRequestedEvent, PullRequestSynchronizeEvent, PullRequestUnassignedEvent, PullRequestUnlabeledEvent, PullRequestUnlockedEvent, PullRequestReviewEvent, PullRequestReviewDismissedEvent, PullRequestReviewEditedEvent, PullRequestReviewSubmittedEvent, PullRequestReviewCommentEvent, PullRequestReviewCommentCreatedEvent, PullRequestReviewCommentDeletedEvent, PullRequestReviewCommentEditedEvent, PushEvent, ReleaseEvent, ReleaseCreatedEvent, ReleaseDeletedEvent, ReleaseEditedEvent, ReleasePrereleasedEvent, ReleasePublishedEvent, ReleaseReleasedEvent, ReleaseUnpublishedEvent, RepositoryEvent, RepositoryArchivedEvent, RepositoryCreatedEvent, RepositoryDeletedEvent, RepositoryEditedEvent, RepositoryPrivatizedEvent, RepositoryPublicizedEvent, RepositoryRenamedEvent, RepositoryTransferredEvent, RepositoryUnarchivedEvent, RepositoryDispatchEvent, RepositoryDispatchOnDemandTestEvent, RepositoryImportEvent, RepositoryVulnerabilityAlertEvent, RepositoryVulnerabilityAlertCreateEvent, RepositoryVulnerabilityAlertDismissEvent, RepositoryVulnerabilityAlertResolveEvent, SecretScanningAlertEvent, SecretScanningAlertCreatedEvent, SecretScanningAlertReopenedEvent, SecretScanningAlertResolvedEvent, SecurityAdvisoryEvent, SecurityAdvisoryPerformedEvent, SecurityAdvisoryPublishedEvent, SecurityAdvisoryUpdatedEvent, SponsorshipEvent, SponsorshipCancelledEvent, SponsorshipCreatedEvent, SponsorshipEditedEvent, SponsorshipPendingCancellationEvent, SponsorshipPendingTierChangeEvent, SponsorshipTierChangedEvent, StarEvent, StarCreatedEvent, StarDeletedEvent, StatusEvent, TeamEvent, TeamAddedToRepositoryEvent, TeamCreatedEvent, TeamDeletedEvent, TeamEditedEvent, TeamRemovedFromRepositoryEvent, TeamAddEvent, WatchEvent, WatchStartedEvent, WorkflowDispatchEvent, WorkflowRunEvent, WorkflowRunCompletedEvent, WorkflowRunRequestedEvent } from "@octokit/webhooks-definitions/schema";
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/index.d.ts:18:56 - error TS2537: Type 'EmitterWebhookEventMap' has no matching index signature for type 'number'.

18     verifyAndReceive: (options: EmitterWebhookEventMap[WebhookEventName] & {
                                                          ~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/index.d.ts:18:56 - error TS2537: Type 'EmitterWebhookEventMap' has no matching index signature for type 'string'.

18     verifyAndReceive: (options: EmitterWebhookEventMap[WebhookEventName] & {
                                                          ~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/index.d.ts:18:56 - error TS2538: Type 'symbol' cannot be used as an index type.

18     verifyAndReceive: (options: EmitterWebhookEventMap[WebhookEventName] & {
                                                          ~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/middleware/verify-and-receive.d.ts:1:33 - error TS2307: Cannot find module '@octokit/webhooks-definitions/schema' or its corresponding type declarations.

1 import { EventPayloadMap } from "@octokit/webhooks-definitions/schema";
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/middleware/verify-and-receive.d.ts:4:86 - error TS2537: Type 'EmitterWebhookEventMap' has no matching index signature for type 'number'.

4 export declare function verifyAndReceive(state: State, event: EmitterWebhookEventMap[WebhookEventName] & {
                                                                                       ~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/middleware/verify-and-receive.d.ts:4:86 - error TS2537: Type 'EmitterWebhookEventMap' has no matching index signature for type 'string'.

4 export declare function verifyAndReceive(state: State, event: EmitterWebhookEventMap[WebhookEventName] & {
                                                                                       ~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/middleware/verify-and-receive.d.ts:4:86 - error TS2538: Type 'symbol' cannot be used as an index type.

4 export declare function verifyAndReceive(state: State, event: EmitterWebhookEventMap[WebhookEventName] & {
                                                                                       ~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/types.d.ts:2:29 - error TS2307: Cannot find module '@octokit/webhooks-definitions/schema' or its corresponding type declarations.

2 import type { Schema } from "@octokit/webhooks-definitions/schema";
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/probot/lib/context.d.ts:1:25 - error TS2724: '"../../@octokit/webhooks/dist-types"' has no exported member named 'WebhookEvent'. Did you mean 'WebhookEvents'?

1 import { EventPayloads, WebhookEvent } from "@octokit/webhooks";
                          ~~~~~~~~~~~~

node_modules/probot/lib/probot.d.ts:2:10 - error TS2724: '"../../@octokit/webhooks/dist-types"' has no exported member named 'WebhookEvent'. Did you mean 'WebhookEvents'?

2 import { WebhookEvent } from "@octokit/webhooks";
           ~~~~~~~~~~~~

node_modules/probot/lib/types.d.ts:2:10 - error TS2724: '"../../@octokit/webhooks/dist-types"' has no exported member named 'WebhookEvent'. Did you mean 'WebhookEvents'?

2 import { WebhookEvent, Webhooks } from "@octokit/webhooks";
           ~~~~~~~~~~~~

src/owl-bot.ts:68:15 - error TS2339: Property 'octokit' does not exist on type 'BaseWebhookEvent<"pull_request"> & Pick<Context<any>, never>'.

68       context.octokit
                 ~~~~~~~

src/owl-bot.ts:83:15 - error TS2339: Property 'octokit' does not exist on type 'BaseWebhookEvent<"pull_request"> & Pick<Context<any>, never>'.

83       context.octokit
                 ~~~~~~~

src/owl-bot.ts:98:15 - error TS2339: Property 'octokit' does not exist on type 'BaseWebhookEvent<"pull_request"> & Pick<Context<any>, never>'.

98       context.octokit
                 ~~~~~~~

src/owl-bot.ts:102:35 - error TS2345: Argument of type '(context: PubSubContext) => Promise<void>' is not assignable to parameter of type 'HandlerFunction<any, Pick<Context<any>, never>>'.
  Types of parameters 'context' and 'event' are incompatible.
    Type '(BaseWebhookEvent<"pull_request"> & Pick<Context<any>, never>) | (BaseWebhookEvent<"push"> & Pick<Context<any>, never>) | ... 203 more ... | (WebhookEventHandlerError & Pick<...>)' is not assignable to type 'PubSubContext'.
      Type 'BaseWebhookEvent<"pull_request"> & Pick<Context<any>, never>' is missing the following properties from type 'PubSubContext': github, event, log

102   app.on('pubsub.message' as any, async (context: PubSubContext) => {
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What did you expect to happen?

Compilation continues to work.

What the problem might be

The problem seems to be an interdependency between @octokit/rest and probot.

@bcoe bcoe added the Type: Bug Something isn't working as documented, or is being fixed label Feb 4, 2021
@ghost ghost added this to Bugs in JS Feb 4, 2021
@G-Rath
Copy link
Member

G-Rath commented Feb 4, 2021

This looks like an issue with probot, probably that they need to update their types to support the new version.

It'd be really helpful if you could provide a small repo reproducing the problem, so that we can look at what dependencies are being used :)

@gr2m
Copy link
Contributor

gr2m commented Feb 4, 2021

@bcoe might it be related to the custom event names you were using? I think we event types became more restrictive recently in @octokit/webhooks, and we don't yet have APIs to add custom events

@bcoe
Copy link
Author

bcoe commented Feb 4, 2021

@G-Rath with regards to a reproduction, the tests in this application will pass currently:

https://github.com/googleapis/repo-automation-bots/tree/master/packages/owl-bot

But, if you:

npm i @octokit/webhooks@latest
npm t

The compilation exceptions will happen.


might it be related to the custom event names you were using?

@gr2m it seems like this error might be related to the custom handler name:

src/owl-bot.ts:102:35 - error TS2345: Argument of type '(context: PubSubContext) => Promise<void>' is not assignable to parameter of type 'HandlerFunction<any, Pick<Context<any>, never>>'.
  Types of parameters 'context' and 'event' are incompatible.
    Type '(BaseWebhookEvent<"pull_request"> & Pick<Context<any>, never>) | (BaseWebhookEvent<"push"> & Pick<Context<any>, never>) | ... 203 more ... | (WebhookEventHandlerError & Pick<...>)' is not assignable to type 'PubSubContext'.
      Type 'BaseWebhookEvent<"pull_request"> & Pick<Context<any>, never>' is missing the following properties from type 'PubSubContext': github, event, log

102   app.on('pubsub.message' as any, async (context: PubSubContext) => {
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

But the rest of the errors seem to be happening regardless of whether I configure a custom event name or not:

node_modules/probot/lib/types.d.ts:2:10 - error TS2724: '"../../@octokit/webhooks/dist-types"' has no exported member named 'WebhookEvent'. Did you mean 'WebhookEvents'?

2 import { WebhookEvent, Webhooks } from "@octokit/webhooks";

@wolfy1339
Copy link
Member

wolfy1339 commented Feb 4, 2021

One of the issues, is that we require @octokit/webhook-definitions in the types exported in this repo and we list it as a devDep, and when people come to use our types, they have to depend on @octokit/webhook-definitions themselves.

Since probot requires @octokit/webhooks and the version range is set to ^7.18.1 (which means anything with the major version of 7), and the new types were released in a feature release, things will break for people who use typescript when they do fresh installs of probot or update their dependencies in package-lock.json

@G-Rath
Copy link
Member

G-Rath commented Feb 4, 2021

One of the issues, is that we require @octokit/webhook-definitions in the types exported in this repo and we list it as a devDep,

🤦 That is completely my fault - I should have moved it to dependencies in my PR, or at least put it in peerDependencies.

@bcoe
Copy link
Author

bcoe commented Feb 4, 2021

It seems like there's maybe a couple unrelated hiccups biting me:

  • @gr2m is right about the custom webhook name causing an issue, but I seem to be able to work around it by casting to any.
  • it looks like the types think that octokit is no longer a property on the context passed into a webhook:
src/owl-bot.ts:98:15 - error TS2339: Property 'octokit' does not exist on type 'BaseWebhookEvent<"pull_request"> & Pick<Context<any>, never>'.

98       context.octokit
  • these issues seem like perhaps the exporting issue being mentioned:
node_modules/@octokit/webhooks/dist-types/middleware/verify-and-receive.d.ts:4:86 - error TS2538: Type 'symbol' cannot be used as an index type.

4 export declare function verifyAndReceive(state: State, event: EmitterWebhookEventMap[WebhookEventName] & {
                                                                                       ~~~~~~~~~~~~~~~~

node_modules/@octokit/webhooks/dist-types/types.d.ts:2:29 - error TS2307: Cannot find module '@octokit/webhooks-definitions/schema' or its corresponding type declarations.

2 import type { Schema } from "@octokit/webhooks-definitions/schema";
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/probot/lib/context.d.ts:1:25 - error TS2724: '"../../@octokit/webhooks/dist-types"' has no exported member named 'WebhookEvent'. Did you mean 'WebhookEvents'?

1 import { EventPayloads, WebhookEvent } from "@octokit/webhooks";

Hope this helps, happy to keep running tests on my end 😄

Thanks for the super fast response.

@wolfy1339
Copy link
Member

The remaining issues are with probot itself and are unrelated to here

@wolfy1339
Copy link
Member

probot/probot#1472 should prevent some of the errors you've experienced from happening until probot is updated with the new types

@gr2m
Copy link
Contributor

gr2m commented Feb 4, 2021

it looks like the types think that octokit is no longer a property on the context passed into a webhook:

that might be related to the new Webhooks type arguments we introduced at some point and I really want to get rid of them: #440

@G-Rath
Copy link
Member

G-Rath commented Feb 4, 2021

So I've checked this out locally, and I think it's just a case of probot needing an update.

Property 'octokit' does not exist on type

This happens because of the initial import failures, which means TypeScript can't finish resolving the types properly.

Upon "fixing" those, you get better errors that indicate the property does exist:

src/owl-bot.ts:102:35 - error TS2345: Argument of type '(context: PubSubContext) => Promise<void>' is not assignable to parameter of type 'HandlerFunction<any, Pick<Context<any>, "issue" | "repo" | "name" | "id" | "config" | "payload" | "octokit" | "log" | "pullRequest" | "isBot">>'.
  Types of parameters 'context' and 'event' are incompatible.
    Type '(BaseWebhookEvent<"pull_request"> & Pick<Context<any>, "issue" | "repo" | "name" | "id" | "config" | "payload" | "octokit" | "log" | "pullRequest" | "isBot">) | ... 203 more ... | (BaseWebhookEvent<...> & Pick<...>)' is not assignable to type 'PubSubContext'.
      Type 'BaseWebhookEvent<"pull_request"> & Pick<Context<any>, "issue" | "repo" | "name" | "id" | "config" | "payload" | "octokit" | "log" | "pullRequest" | "isBot">' is missing the following properties from type 'PubSubContext': github, event

102   app.on('pubsub.message' as any, async (context: PubSubContext) => {

overall, getting those import problems should be the first thing anyone does before looking into this further, as they greatly impact what errors happen since TypeScript won't have the right types in some places, causing it to give up inference which'll lead to other errors (i.g. like "property does not exist")

@bcoe
Copy link
Author

bcoe commented Feb 5, 2021

Testing with the latest versions of probot, etc., and I seem to be able to compile again 👍

Thank you for your help.

@bcoe bcoe closed this as completed Feb 5, 2021
JS automation moved this from Bugs to Done Feb 5, 2021
@retorquere
Copy link

Can I use a type guard to inform the typescript compiler that I have e.g. a IssueCommentEvent or an IssueCommentCreatedEvent? There's no type field or somesuch that I could use I think.

@wolfy1339
Copy link
Member

Next time, please open up a new issue.

You shouldn't need to inform the TS compiler of what event you have, it's inferred automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented, or is being fixed
Projects
No open projects
JS
  
Done
Development

No branches or pull requests

5 participants