Commit 7f7d57b

HPCesia <me@hpcesia.com>
2025-03-18 11:56:48
refactor: declare twikoo global variable
1 parent cd6071d
Changed files (2)
src
components
src/components/comment/Twikoo.astro
@@ -8,8 +8,6 @@ import { CDN } from '@constants/cdn.mjs';
 <script>
   import { commentConfig } from '@/config';
   const twikooConfig = commentConfig.twikoo;
-  // eslint-disable-next-line @typescript-eslint/no-explicit-any
-  declare const twikoo: any;
 
   function setup() {
     if (typeof twikoo === 'undefined') {
@@ -17,7 +15,7 @@ import { CDN } from '@constants/cdn.mjs';
     } else {
       twikoo.init({
         el: '#twikoo-wrap',
-        ...twikooConfig,
+        ...twikooConfig!,
       });
     }
   }
src/global.d.ts
@@ -4,4 +4,39 @@ declare global {
   interface Window {
     swup: Swup;
   }
+
+  const twikoo: {
+    init: (options: {
+      envId: string;
+      el: string;
+      region?: string;
+      path?: string;
+      lang?: string;
+      onCommentLoaded?: () => void;
+    }) => Promise<void>;
+    getCommentsCount: (options: {
+      envId: string;
+      urls: string[];
+      includeReply?: boolean;
+    }) => Promise<{ url: string; count: number }[]>;
+    getRecentComments: (options: {
+      envId: string;
+      urls?: string[];
+      pageSize?: number;
+      includeReply?: boolean;
+    }) => Promise<
+      {
+        id: string;
+        url: string;
+        nick: string;
+        mailMd5: string;
+        link: string;
+        comment: string;
+        commentText: string;
+        created: number;
+        avatar: string;
+        relativeTime: string;
+      }[]
+    >;
+  };
 }