Skip to content

Commit bf1510b

Browse files
committed
Add types for window.FrontChat
1 parent ae1ae5b commit bf1510b

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/providers/front.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ import waitForLoad from '../utils/waitForLoad'
66

77
declare global {
88
interface Window {
9-
//eslint-disable-next-line @typescript-eslint/no-explicit-any
10-
FrontChat: any
9+
FrontChat?: {
10+
(
11+
command: string,
12+
params?: Record<string, string | boolean | object>
13+
): void
14+
// This isn't part of the FrontChat API; we add it to track when Front is fully initialized
15+
hasInitialized: boolean
16+
}
1117
}
1218
}
1319

@@ -46,13 +52,12 @@ const load = ({
4652
const loaded = loadScript(() => {
4753
beforeInit()
4854

49-
window.FrontChat('init', {
55+
window.FrontChat?.('init', {
5056
chatId: providerKey,
5157
onInitCompleted: () => {
5258
setState('complete')
5359
onReady()
54-
// 👇 Add state to Track when Front is fully initialized
55-
window.FrontChat.hasInitialized = true
60+
if (window.FrontChat) window.FrontChat.hasInitialized = true
5661
}
5762
//Read more: https://dev.frontapp.com/docs/chat-sdk-reference
5863
})
@@ -62,8 +67,8 @@ const load = ({
6267

6368
const open = (): void => {
6469
waitForLoad(
65-
() => window.FrontChat?.hasInitialized,
66-
() => window.FrontChat('show')
70+
() => !!window.FrontChat?.hasInitialized,
71+
() => window.FrontChat?.('show')
6772
)
6873
}
6974

0 commit comments

Comments
 (0)