Skip to content

Stream typescript auto-generated definitions #41

Open
serverless/serverless
#9297

Description

@fredericbarthelet

Not a directly related question but I would appreciate your guidance. Now that type definitions are auto-generated, certain things are much clearer and certain things are not. Please take a look at stream event definition:

I do this:

      events: [
        {
          stream: {
            arn: {
              'Fn::GetAtt': ['MyTable', 'StreamArm'],
            },
            batchSize: 1,
          },
        },
      ],

and serverless fails fast on functions.propagate.events[0].stream.arn': should be string with configValidationMode: 'error'. If I turn off configValidationMode, serverless package fails on EventSourceArn.split is not a function. This has been talked about long time ago here serverless/serverless#2365 and later fixed here serverless/serverless#3111.

The fix was simple - adding an explicit type attribute to the stream event definition. DefinitelyTyped has it (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/serverless/plugins/aws/provider/awsProvider.d.ts#L408):

    interface Stream {
        arn: string | { [key: string]: any };
        batchSize?: number | string;
        startingPosition?: number | string;
        enabled?: boolean;
        type?: 'dynamodb' | 'kinesis';
    }

but it's lost in auto-generated types:

        {
            stream:
              | AwsArnString
              | (
                  | {
                      arn: AwsCfFunction;
                      [k: string]: unknown;
                    }
                  | {
                      arn: AwsArnString;
                      [k: string]: unknown;
                    }
                );
          }

So my question is - where to submit a PR or an Issue to get back those typed attributes into the generated type definitions? Adding type solved my problem but it would be nice if it was visible on the type def and thus accessible via auto-complete

Thanks!

Originally posted by @pveller in #38 (comment)

Activity

  1. fredericbarthelet commented on Apr 13, 2021

    @fredericbarthelet
    ContributorAuthor

    Hi @pveller and thanks for reporting your issue.
    Regarding your issue, the code that will be used for typescript definition generation is https://github.com/serverless/serverless/blob/19805d71eabb68bd7fd4046aa23090ef85fb1c36/lib/plugins/aws/package/compile/events/stream.js#L15-L90

    This JSON schema definition can be improved to ensure generated type stills give you information on the expected type property. I give such an exemple in the PR I just opened.

    In the future, do not hesitate to open a separate issue with your problem description (which was very clear by the way :) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions