generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 69
refactor(cli): remove generic argument from notify<T>()
#217
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mrgrain
reviewed
Mar 10, 2025
packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/io-helper.ts
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
8e5e04a to
298f208
Compare
auto-merge was automatically disabled
March 10, 2025 14:50
Pull request was closed
mrgrain
reviewed
Mar 10, 2025
packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/io-helper.ts
Outdated
Show resolved
Hide resolved
notify<T>()notify<T>()
mrgrain
approved these changes
Mar 10, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
IIoHostinterface has the following method:The generic parameter
Tis only used once, without bounds, for a singleton argument in input position. This means it is equivalent to the following:(Preferring
unknownoveranyso that implementors are forced to test for the type of thedatafield, just like they would need to do with an argument of typeT)In the words of the Java generics tutorial:
Or similar advice for TypeScript:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license