You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(cli): remove generic argument from notify<T>() (#217)
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.
---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license
---------
Co-authored-by: Momo Kornher <[email protected]>
0 commit comments