Skip to content
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

feat(event): enhance FrameworkEventInitType type definition #2171

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/event-improve-type-resolve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@equinor/fusion-event": patch
---

## @equinor/fusion-event

### Improved Type Resolution for `FrameworkEventInitType`

The `FrameworkEventInitType` type has been enhanced to better resolve types for both `IFrameworkEvent` and `FrameworkEvent`.

When defining events `FrameworkEventMap`, the dispatch type can now be inferred from the event type.

#### Changes

The type definition for `FrameworkEventInitType` has been updated as follows:

```typescript
export type FrameworkEventInitType<T> =
T extends IFrameworkEvent<infer U> ? U : T extends FrameworkEvent<infer U> ? U : never;
```

This change ensures that `FrameworkEventInitType` can now correctly infer the type for both `IFrameworkEvent` and `FrameworkEvent`.
3 changes: 2 additions & 1 deletion packages/modules/event/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export type FrameworkEventInit<TDetail = any, TSource = any> = {
};

/** defer init type args of event */
export type FrameworkEventInitType<T> = T extends IFrameworkEvent<infer U> ? U : never;
export type FrameworkEventInitType<T> =
T extends IFrameworkEvent<infer U> ? U : T extends FrameworkEvent<infer U> ? U : never;

/** defer name type of event */
export type FrameworkEventType<T> =
Expand Down
1 change: 1 addition & 0 deletions packages/modules/event/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type {
FrameworkEventSource,
FrameworkEventMap,
FrameworkEventHandler,
FrameworkEventInitType,
} from './event';

export { IEventModuleConfigurator } from './configurator';
Expand Down
Loading