Skip to content

Commit

Permalink
feat(api): improve EventName type definition (#2379)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 10, 2021
1 parent b9a9de6 commit 8e48029
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/improve-api-types.md
@@ -0,0 +1,5 @@
---
"api": patch
---

Improve `EventName` type using `type-fest`'s `LiteralUnion`.
1 change: 1 addition & 0 deletions tooling/api/package.json
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions tooling/api/src/event.ts
Expand Up @@ -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 */
Expand All @@ -22,7 +23,7 @@ interface Event<T> {
payload: T
}

type EventName =
type EventName = LiteralUnion<
| 'tauri://update'
| 'tauri://update-available'
| 'tauri://update-install'
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/window.ts
Expand Up @@ -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)
})
Expand Down
3 changes: 2 additions & 1 deletion tooling/api/tsconfig.json
Expand Up @@ -10,7 +10,8 @@
},
"declaration": true,
"declarationDir": "dist",
"rootDir": "src"
"rootDir": "src",
"moduleResolution": "node"
},
"include": ["./src"]
}
5 changes: 5 additions & 0 deletions tooling/api/yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit 8e48029

Please sign in to comment.