Skip to content

Error when import type #936

@throrin19

Description

@throrin19

Reproduction link or steps

have serverless installed with his types :

npm i -DE @types/serverless@3.12.28 
npm i -DE serverless@4.33.0

Have a file with import the IamRoleStatement type :

import type { IamRoleStatement } from 'serverless/aws.d.ts';

/*
`arn:aws:s3:::${aws.s3.uploader}`,
        `arn:aws:s3:::${aws.s3.uploader}/*`,
 */

export interface GenerateStmntOpts {
    /**
     * Type of resource
     */
    type: 'apigateway' | 's3' | 'sns' | 'sqs';
    /**
     * List of resources impacted by the rights
     */
    resources: object[] | string[];
    /**
     * List of rights
     */
    rights: string[];
}

export type Statement = RequireOne<IamRoleStatement, 'Action' | 'Resource'>;

/**
 * Generate IamRoleStatement to add permissions to specific function.
 * This function should be used exclusivelly in serverless part and not handlers part.
 *
 * @param options - Function parameters
 * @returns A complete desired IamRoleStatement
 */
export const generateStatement = (options: GenerateStmntOpts): Statement => {
    const finalResources = options.resources.map((res) => {
        if (res === '*') {
            return res;
        }

        /* istanbul ignore else -- @preserve */
        if (options.type === 's3') {
            return `arn:aws:s3:::${res}`;
        }

        /* istanbul ignore next -- @preserve */
        return res;
    });

    return {
        Action: options.rights,
        Effect: 'Allow',
        Resource: finalResources,
    };
};

Used tsdown.config.ts :

import { defineConfig } from 'tsdown';

export default defineConfig({
    dts: { build: true },
    format: 'esm',
    inlineOnly: false,
    treeshake: true,
});

Try to compile this project

What is expected?

No error on compilation

What is actually happening?

Since upgrade tsdown from 0.21.9 to 0.21.10, I have this error in my project on build :

Image

But I import a type in the source ts file :

import type { IamRoleStatement } from 'serverless/aws.d.ts';

/*
`arn:aws:s3:::${aws.s3.uploader}`,
        `arn:aws:s3:::${aws.s3.uploader}/*`,
 */

export interface GenerateStmntOpts {
    /**
     * Type of resource
     */
    type: 'apigateway' | 's3' | 'sns' | 'sqs';
    /**
     * List of resources impacted by the rights
     */
    resources: object[] | string[];
    /**
     * List of rights
     */
    rights: string[];
}

export type Statement = RequireOne<IamRoleStatement, 'Action' | 'Resource'>;

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions