File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 1
1
import type { CommentTableRow } from '@/entrypoints/background'
2
- import type { CommentEvent } from './enhancer'
2
+ import type { CommentEvent , CommentEventType } from './enhancer'
3
3
4
4
// Message handler response types
5
5
export const CLOSE_MESSAGE_PORT = false as const // No response will be sent
@@ -29,12 +29,24 @@ export interface GetTableRowsResponse {
29
29
rows : CommentTableRow [ ]
30
30
}
31
31
32
+ // Exhaustive list of valid comment event types - TypeScript will error if CommentEventType changes
33
+ const COMMENT_EVENT_TYPES = {
34
+ DESTROYED : true ,
35
+ ENHANCED : true ,
36
+ LOST_FOCUS : true ,
37
+ } as const satisfies Record < CommentEventType , true >
38
+
39
+ // Helper function to check if a string is a valid CommentEventType
40
+ function isValidCommentEventType ( type : string ) : type is CommentEventType {
41
+ return type in COMMENT_EVENT_TYPES
42
+ }
43
+
32
44
// Type guard functions
33
45
export function isContentToBackgroundMessage ( message : any ) : message is ContentToBackgroundMessage {
34
46
return (
35
47
message &&
36
48
typeof message . type === 'string' &&
37
- ( message . type === 'ENHANCED' || message . type === 'DESTROYED' ) &&
49
+ isValidCommentEventType ( message . type ) &&
38
50
message . spot
39
51
)
40
52
}
You can’t perform that action at this time.
0 commit comments