Skip to content

Conversation

@rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Mar 10, 2025

The IIoHost interface has the following method:

interface IIoHost {
  notify<T>(msg: IoMessage<T>): Promise<void>;
}

The generic parameter T is only used once, without bounds, for a singleton argument in input position. This means it is equivalent to the following:

interface IIoHost {
  notify(msg: IoMessage<unknown>): Promise<void>;
}

(Preferring unknown over any so that implementors are forced to test for the type of the data field, just like they would need to do with an argument of type T)

In the words of the Java generics tutorial:

Generic methods allow type parameters to be used to express
dependencies among the types of one or more arguments to a method and/or
its return type. If there isn't such a dependency, a generic method
should not be used.

Or similar advice for TypeScript:

Type Parameters Should Appear Twice

Type parameters are for relating the types of multiple values. If a
type parameter is only used once in the function signature, it's not
relating anything.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@rix0rrr rix0rrr requested a review from a team March 10, 2025 12:16
@aws-cdk-automation aws-cdk-automation requested a review from a team March 10, 2025 12:17
@github-actions github-actions bot added the p2 label Mar 10, 2025
@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.08%. Comparing base (4566d8d) to head (1b7d105).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/aws-cdk/lib/cli/activity-printer/base.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
+ Coverage   85.02%   85.08%   +0.05%     
==========================================
  Files         208      208              
  Lines       35657    35657              
  Branches     4630     4621       -9     
==========================================
+ Hits        30318    30337      +19     
+ Misses       5181     5167      -14     
+ Partials      158      153       -5     
Flag Coverage Δ
suite.unit 85.08% <85.71%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The `IIoHost` interface has the following method:

```ts
interface IIoHost {
  notify<T>(msg: IoMessage<T>): Promise<void>;
}
```

The generic parameter `T` is only used once, without bounds, for a
singleton argument in input position. This means it is equivalent to the
following:

```ts
interface IIoHost {
  notify(msg: IoMessage<unknown>): Promise<void>;
}
```

(Preferring `unknown` over `any` so that implementors are forced to
test for the type of the `data` field, just like they would need
to do with an argument of type `T`)

In the words of the [Java generics
tutorial](https://docs.oracle.com/javase/tutorial/extra/generics/methods.html):

> Generic methods allow type parameters to be used to express
> dependencies among the types of one or more arguments to a method and/or
> its return type. If there isn't such a dependency, a generic method
> should not be used.

Or [similar advice for
TypeScript](https://effectivetypescript.com/2020/08/12/generics-golden-rule/):

> Type Parameters Should Appear Twice
>
> Type parameters are for relating the types of multiple values. If a
> type parameter is only used once in the function signature, it's not
> relating anything.
@rix0rrr rix0rrr force-pushed the huijbers/drop-generic-arg branch from 8e5e04a to 298f208 Compare March 10, 2025 12:59
@rix0rrr rix0rrr added the pr/exempt-integ-test Skips the integ test steps if set. label Mar 10, 2025
@rix0rrr rix0rrr closed this Mar 10, 2025
auto-merge was automatically disabled March 10, 2025 14:50

Pull request was closed

@rix0rrr rix0rrr reopened this Mar 10, 2025
@mrgrain mrgrain changed the title refactor: remove generic argument from notify<T>() refactor(cli): remove generic argument from notify<T>() Mar 10, 2025
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Mar 10, 2025
Merged via the queue into main with commit e20f1a8 Mar 10, 2025
14 checks passed
@aws-cdk-automation aws-cdk-automation deleted the huijbers/drop-generic-arg branch March 10, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2 pr/exempt-integ-test Skips the integ test steps if set.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants