feat(api): improve EventName type definition (#2379)

This commit is contained in:
Lucas Fernandes Nogueira 2021-08-10 10:54:42 -03:00 committed by GitHub
parent b9a9de6b64
commit 8e48029790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
"api": patch
---
Improve `EventName` type using `type-fest`'s `LiteralUnion`.

View File

@ -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"

View File

@ -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

View File

@ -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)
})

View File

@ -10,7 +10,8 @@
},
"declaration": true,
"declarationDir": "dist",
"rootDir": "src"
"rootDir": "src",
"moduleResolution": "node"
},
"include": ["./src"]
}

View File

@ -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"