mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 12:27:16 +03:00
feat(api): improve EventName
type definition (#2379)
This commit is contained in:
parent
b9a9de6b64
commit
8e48029790
5
.changes/improve-api-types.md
Normal file
5
.changes/improve-api-types.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"api": patch
|
||||
---
|
||||
|
||||
Improve `EventName` type using `type-fest`'s `LiteralUnion`.
|
@ -66,6 +66,7 @@
|
||||
"rollup": "2.56.1",
|
||||
"rollup-plugin-terser": "7.0.2",
|
||||
"tslib": "2.3.0",
|
||||
"type-fest": "2.0.0",
|
||||
"typedoc": "0.21.5",
|
||||
"typedoc-plugin-markdown": "3.10.4",
|
||||
"typescript": "4.3.5"
|
||||
|
@ -12,6 +12,7 @@
|
||||
import { invokeTauriCommand } from './helpers/tauri'
|
||||
import { emit as emitEvent } from './helpers/event'
|
||||
import { transformCallback } from './tauri'
|
||||
import { LiteralUnion } from 'type-fest'
|
||||
|
||||
interface Event<T> {
|
||||
/** Event name */
|
||||
@ -22,7 +23,7 @@ interface Event<T> {
|
||||
payload: T
|
||||
}
|
||||
|
||||
type EventName =
|
||||
type EventName = LiteralUnion<
|
||||
| 'tauri://update'
|
||||
| 'tauri://update-available'
|
||||
| 'tauri://update-install'
|
||||
@ -37,8 +38,9 @@ type EventName =
|
||||
| 'tauri://menu'
|
||||
| 'tauri://file-drop'
|
||||
| 'tauri://file-drop-hover'
|
||||
| 'tauri://file-drop-cancelled'
|
||||
| string
|
||||
| 'tauri://file-drop-cancelled',
|
||||
string
|
||||
>
|
||||
|
||||
type EventCallback<T> = (event: Event<T>) => void
|
||||
|
||||
|
@ -249,7 +249,7 @@ class WebviewWindowHandle {
|
||||
): Promise<UnlistenFn> {
|
||||
if (this._handleTauriEvent(event, handler)) {
|
||||
return Promise.resolve(() => {
|
||||
// eslint-disable-next-line security/detect-object-injection
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, security/detect-object-injection
|
||||
const listeners = this.listeners[event]
|
||||
listeners.splice(listeners.indexOf(handler), 1)
|
||||
})
|
||||
|
@ -10,7 +10,8 @@
|
||||
},
|
||||
"declaration": true,
|
||||
"declarationDir": "dist",
|
||||
"rootDir": "src"
|
||||
"rootDir": "src",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["./src"]
|
||||
}
|
||||
|
@ -3377,6 +3377,11 @@ type-check@^0.4.0, type-check@~0.4.0:
|
||||
dependencies:
|
||||
prelude-ls "^1.2.1"
|
||||
|
||||
type-fest@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.0.0.tgz#e9daf5615e89f6d430f34117f88f4ee2cd5a2725"
|
||||
integrity sha512-BoEUnckjP9oiudy3KxlGdudtBAdJQ74Wp7dYwVPkUzBn+cVHOsBXh2zD2jLyqgbuJ1KMNriczZCI7lTBA94dFg==
|
||||
|
||||
type-fest@^0.20.2:
|
||||
version "0.20.2"
|
||||
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4"
|
||||
|
Loading…
Reference in New Issue
Block a user