Skip to content

Commit 1bd3838

Browse files
authored
fix: update readme
1 parent c038c3c commit 1bd3838

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class _Nested {
9696
}
9797

9898
// Enhance the class by specifying the path to nested events
99-
const Nested = AddEvents<typeof _Nested, NestedEvents>(_Nested, 'eventsContainer');
99+
export const Nested = AddEvents<typeof _Nested, NestedEvents>(_Nested, 'eventsContainer');
100+
101+
// Export it as a type as well, to avoid "'Nested' refers to a value, but is being used as a type".
102+
export const Nested = _Nested & WithEventsDummyType(NestedEvents);
100103

101104
// Create an instance and attach event listeners
102105
const instance = new Nested();
@@ -114,15 +117,14 @@ Here’s how errors are managed when an incorrect path is specified:
114117

115118
```typescript
116119
try {
117-
const InvalidClass = AddEvents<typeof Nested, NestedEvents>(Nested, 'incorrectPath');
120+
const InvalidClass = AddEvents<typeof _Nested, NestedEvents>(_Nested, 'incorrectPath');
118121
const wrongInstance = new InvalidClass();
119122
wrongInstance.on('eventOne', () => console.log('This will never run'));
120123
} catch (error) {
121124
console.error(error); // Outputs: Error: Event "incorrectPath.eventOne" is not defined
122125
}
123126
```
124127

125-
126128
## FAQ
127129
##### _Rather than requiring constraints on the type `U` in AddEvents via documentation, why not express them in the type system?_
128130

0 commit comments

Comments
 (0)