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

Minor improvement - remove many non-null assertions #416

Open
TenPotatoes opened this issue Nov 21, 2023 · 0 comments
Open

Minor improvement - remove many non-null assertions #416

TenPotatoes opened this issue Nov 21, 2023 · 0 comments

Comments

@TenPotatoes
Copy link

TenPotatoes commented Nov 21, 2023

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 TenPotatoes changed the title Minor improvement Minor improvement - remove many non-null assertions Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant