Skip to content

Commit 5bbf372

Browse files
committed
add PuppetInterface (#155)
1 parent 47a461e commit 5bbf372

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

src/mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import {
7979

8080
import type {
8181
PuppetImplementation,
82+
PuppetInterface,
8283
} from './puppet/mod.js'
8384

8485
import {
@@ -121,6 +122,7 @@ export type {
121122
MiniProgramPayload,
122123
PuppetEventName,
123124
PuppetImplementation,
125+
PuppetInterface,
124126
PuppetOptions,
125127
RoomInvitationPayload,
126128
RoomMemberPayload,

src/puppet/interface.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { Constructor } from 'clone-class'
2+
3+
import type { Puppet } from './mod.js'
4+
5+
/**
6+
* Mixin: Property 'messageRawPayload' of exported class expression may not be private or protected.ts(4094) #155
7+
* https://github.com/wechaty/puppet/issues/155
8+
*
9+
* We can not use `private` or `protected` to declare Mixins
10+
* So we define a `ProtectedMethods` list to mark the protected methods
11+
* And Omit them from the Puppet typing defination
12+
* to build a new PuppetInterface
13+
*/
14+
type ProtectedMethods = never
15+
| 'cacheContactPayload'
16+
| 'cacheFriendshipPayload'
17+
| 'cacheMessagePayload'
18+
| 'cacheRoomPayload'
19+
| 'cacheRoomMemberPayload'
20+
| 'cacheRoomInvitationPayload'
21+
| 'counter'
22+
| 'memory'
23+
| 'login'
24+
| 'contactRawPayload'
25+
| 'contactRawPayloadParser'
26+
| 'contactQueryFilterFactory'
27+
| 'contactPayloadCache'
28+
| 'friendshipRawPayload'
29+
| 'friendshipRawPayloadParser'
30+
| 'friendshipPayloadCache'
31+
| 'messageRawPayload'
32+
| 'messageRawPayloadParser'
33+
| 'messagePayloadCache'
34+
| 'messageQueryFilterFactory'
35+
| 'roomInvitationPayloadCache'
36+
| 'roomInvitationRawPayload'
37+
| 'roomInvitationRawPayloadParser'
38+
| 'roomRawPayload'
39+
| 'roomRawPayloadParser'
40+
| 'roomMemberRawPayload'
41+
| 'roomMemberRawPayloadParser'
42+
| 'roomQueryFilterFactory'
43+
| 'roomPayloadCache'
44+
45+
// https://stackoverflow.com/questions/44983560/how-to-exclude-a-key-from-an-interface-in-typescript
46+
type PuppetInterface = Omit<Puppet, ProtectedMethods>
47+
48+
type PuppetImplementation = Constructor<PuppetInterface>
49+
50+
export type {
51+
PuppetImplementation,
52+
PuppetInterface,
53+
}

src/puppet/mod.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { PuppetSkelton } from './skelton.js'
22
import {
33
Puppet,
4-
PuppetImplementation,
54
} from './puppet.js'
5+
import type {
6+
PuppetImplementation,
7+
PuppetInterface,
8+
} from './interface.js'
69

710
export type {
811
PuppetImplementation,
12+
PuppetInterface,
913
}
1014
export {
1115
Puppet,

src/puppet/puppet.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,6 @@ abstract class Puppet extends MixinBase {
344344

345345
}
346346

347-
type PuppetImplementation = Constructor<Puppet>
348-
349-
export type {
350-
PuppetImplementation,
351-
}
352347
export {
353348
Puppet,
354349
}

0 commit comments

Comments
 (0)