Commit 1ee0ddb
committed
refactor: remove generic argument from
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.notify<T>()
1 parent e20f1a8 commit 1ee0ddb
File tree
1 file changed
+1
-0
lines changed- packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private
1 file changed
+1
-0
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
0 commit comments