Skip to content

Commit

Permalink
Add a TypeScript test for invoke-without-reject
Browse files Browse the repository at this point in the history
  • Loading branch information
Bannerets committed Jun 8, 2024
1 parent 042bb53 commit cd52570
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/types/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,23 @@ main().catch(console.error)
// Td.formattedText <: Td.formattedText$Input
declare var fmt: Td.formattedText
const fmtInp: Td.formattedText$Input = fmt

const invoke: <T extends Td.$FunctionName>(
query: { readonly _: T } & Td.$FunctionInputByName[T]
) => Promise<Td.$FunctionResultByName[T] | Td.error> = (
req: any
): any =>
client.invoke(req).catch(e => {
if (e instanceof tdl.TDLibError)
return { _: e._, code: e.code, message: e.message }
throw e
})

async function test () {
const res = await invoke({ _: 'getMe' })
if (res._ === 'error') {
console.error('Error', res.code, res.message)
return
}
console.log('Id:', res.id)
}

0 comments on commit cd52570

Please sign in to comment.