cdk-from-cfn icon indicating copy to clipboard operation
cdk-from-cfn copied to clipboard

Minor improvement - remove many non-null assertions

Open TenPotatoes opened this issue 1 year ago • 0 comments

It's not good to use the non-null assertion operator if we can avoid it, and we can fix the way defaults are applied to props to make this not needed.

We can change the following output

public constructor(scope: cdk.App, id: string, props: NoctStackProps) {
    super(scope, id, props);

    // Applying default props
    props = {
      ...props,
      myProperty: props.myProperty ?? '',

To the below output

public constructor(scope: cdk.App, id: string, originalProps: NoctStackProps) {
    super(scope, id, originalProps);

    // Applying default props
    const props = {
      ...originalProps,
      myProperty: originalProps.myProperty ?? '',

And now props has non nullable types and does not need non-null assertions everywhere.

TenPotatoes avatar Nov 21 '23 17:11 TenPotatoes