Skip to content

Commit 1ee0ddb

Browse files
committed
refactor: remove generic argument from notify<T>()
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.
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 changed

packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/io-helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type ActionLessRequest<T, U> = Omit<IoRequest<T, U>, 'action'>;
1414
*/
1515
export interface IoHelper extends IIoHost {
1616
notify(msg: ActionLessMessage<unknown>): Promise<void>;
17+
notify<T>(msg: ActionLessMessage<T>): Promise<void>;
1718
requestResponse<T, U>(msg: ActionLessRequest<T, U>): Promise<U>;
1819
}
1920

0 commit comments

Comments
 (0)