Skip to content

aws_iam: any parameter type in AccountPrinciple constructor #20288

@simonkarman

Description

@simonkarman

Describe the bug

The AccountPrinciple class as found in: https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-iam/lib/principals.ts#L395 has a construct that takes a single argument which is the accountId the type of this 'account id' parameter is any. Can this parameter be changed to be of type string instead?

Expected Behavior

I expect the following piece of code to give a Type error on the first parameter.

new aws_iam.AccountPrincipal({ hello: 'world' }); // This is currently valid, and should not be, it should throw a TypeError
new aws_iam.AccountPrincipal('0123456789012'); // This is valid, and should be

Current Behavior

Currently, TypeScript does not complain about the code below.

new aws_iam.AccountPrincipal({ hello: 'world' }); // This is currently valid, and should not be, it should throw a TypeError
new aws_iam.AccountPrincipal('0123456789012'); // This is valid, and should be

Reproduction Steps

import { aws_iam } from 'aws-cdk-lib';

new aws_iam.AccountPrincipal('0123456789012');
new aws_iam.AccountPrincipal({ hello: 'world' });

Possible Solution

To fix this we can simply replace any with string in the constructor parameter of the AccountPrinciple class in: https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-iam/lib/principals.ts#L395

But first, we should double check there isn't any reasoning behind this being of type any.

Additional Information/Context

No response

CDK CLI Version

2.16.0 (build 4c77925)

Framework Version

No response

Node.js Version

v14.18.0

OS

MacOS

Language

Typescript

Language Version

3.9.7

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-iamRelated to AWS Identity and Access ManagementbugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions