Skip to content

Commit

Permalink
Remove 'any' types where it makes sense
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-orlik committed May 31, 2024
1 parent fe5937f commit c649039
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type WidgetCallback = () => Promise<string>

interface MCEvent {
readonly name?: string
readonly payload: unknown
readonly payload: Record<string, unknown | undefined>
client: Client
readonly type: string
}
Expand Down Expand Up @@ -54,15 +54,15 @@ interface Manager {
type: ClientEventType,
callback: MCEventListener
): boolean | undefined
get(key: string): Promise<unknown>
set(key: string, value: any): Promise<boolean>
get(key: string): Promise<string | null>
set(key: string, value: string): Promise<boolean>
route(
path: string,
callback: (request: Request | any) => Promise<Response> | Response
): string | undefined
proxy(path: string, target: string): string | undefined
serve(path: string, target: string): string | undefined
useCache(key: string, callback: Function, expiry?: number): Promise<unknown>
useCache(key: string, callback: Function, expiry?: number): Promise<string>
invalidateCache(key: string): Promise<void>
registerEmbed(name: string, callback: EmbedCallback): boolean | undefined
registerWidget(callback: WidgetCallback): boolean | undefined
Expand Down
10 changes: 9 additions & 1 deletion tests/demoComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default async function (manager: Manager, settings: ComponentSettings) {
// Save mouse coordinates as a cookie
const { client, payload } = event
console.info('🐁 ⬇️ Mousedown payload:', payload)
if (!Array.isArray(payload.mousedown)) {
throw new Error('expected mousedown to be an array')
}
const [firstClick] = payload.mousedown
client.set('lastClickX', firstClick.clientX)
client.set('lastClickY', firstClick.clientY)
Expand Down Expand Up @@ -85,7 +88,9 @@ export default async function (manager: Manager, settings: ComponentSettings) {
payload.user_id = client.get('user_id')

if (Object.keys(payload || {}).length) {
const params = new URLSearchParams(payload).toString()
const params = new URLSearchParams(
payload as Record<string, string>
).toString()
fetch(`http://www.example.com/?${params}`)
}
})
Expand Down Expand Up @@ -129,6 +134,9 @@ export default async function (manager: Manager, settings: ComponentSettings) {
console.error('error fetching weather for embed:', error)
}
})
if (typeof embed !== 'string') {
throw new Error('Unexpected embed return type: ' + typeof embed)
}
return embed
}
)
Expand Down

0 comments on commit c649039

Please sign in to comment.