feat: use unknown instead of undefined for type annotations

This commit is contained in:
sxyazi
2025-05-28 17:28:39 +08:00
parent 9d15f24557
commit b3eda26618

View File

@@ -1,7 +1,7 @@
-- luacheck: globals Command Url cx fs ps rt th ui ya -- luacheck: globals Command Url cx fs ps rt th ui ya
---@alias undefined any ---@alias unknown any
---@alias Color string ---@alias Color string
---@alias Direction integer ---@alias Direction integer
@@ -613,7 +613,7 @@ ya = ya
-- | `self` | `Self` | -- | `self` | `Self` |
-- | `align` | [`Align`](#align) | -- | `align` | [`Align`](#align) |
-- | Return | `self` | -- | Return | `self` |
---@field align fun(self: self, align: Align): self ---@field align fun(self: self, align: ui.Align): self
-- Whether the line is visible, i.e. includes any printable characters. -- Whether the line is visible, i.e. includes any printable characters.
-- | In/Out | Type | -- | In/Out | Type |
-- | ------ | --------- | -- | ------ | --------- |
@@ -664,14 +664,14 @@ ya = ya
-- | `self` | `Self` | -- | `self` | `Self` |
-- | `align` | [`Align`](#align) | -- | `align` | [`Align`](#align) |
-- | Return | `self` | -- | Return | `self` |
---@field align fun(self: self, align: Align): self ---@field align fun(self: self, align: ui.Align): self
-- Set the wrap of the text. -- Set the wrap of the text.
-- | In/Out | Type | -- | In/Out | Type |
-- | ------ | --------------- | -- | ------ | --------------- |
-- | `self` | `Self` | -- | `self` | `Self` |
-- | `wrap` | [`Wrap`](#wrap) | -- | `wrap` | [`Wrap`](#wrap) |
-- | Return | `self` | -- | Return | `self` |
---@field wrap fun(self: self, wrap: Wrap): self ---@field wrap fun(self: self, wrap: ui.Wrap): self
-- Calculate the maximum width of the text across all lines. -- Calculate the maximum width of the text across all lines.
-- | In/Out | Type | -- | In/Out | Type |
-- | ------ | --------- | -- | ------ | --------- |
@@ -970,7 +970,7 @@ ya = ya
-- | `style` | [`Style`](#style) | -- | `style` | [`Style`](#style) |
-- | Return | `self` | -- | Return | `self` |
---@field style fun(self: self, style: ui.Style): self ---@field style fun(self: self, style: ui.Style): self
---@overload fun(edge: Edge): ui.Border ---@overload fun(edge: ui.Edge): ui.Border
-- Create a gauge: -- Create a gauge:
-- ```lua -- ```lua
@@ -1042,73 +1042,73 @@ ya = ya
---@overload fun(): ui.Clear ---@overload fun(): ui.Clear
-- Align is used to set the alignment of an element, such as a [Line](#line) or [Text](#text). -- Align is used to set the alignment of an element, such as a [Line](#line) or [Text](#text).
---@class (exact) Align ---@class (exact) ui.Align
-- Align to the left. -- Align to the left.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field LEFT undefined ---@field LEFT unknown
-- Align to the center. -- Align to the center.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field CENTER undefined ---@field CENTER unknown
-- Align to the right. -- Align to the right.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field RIGHT undefined ---@field RIGHT unknown
-- --
---@class (exact) Wrap ---@class (exact) ui.Wrap
-- Disables wrapping. -- Disables wrapping.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field NO undefined ---@field NO unknown
-- Enables wrapping. -- Enables wrapping.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field YES undefined ---@field YES unknown
-- Enables wrapping and trims the leading whitespace. -- Enables wrapping and trims the leading whitespace.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field TRIM undefined ---@field TRIM unknown
-- --
---@class (exact) Edge ---@class (exact) ui.Edge
-- No edge is applied. -- No edge is applied.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field NONE undefined ---@field NONE unknown
-- Applies the top edge. -- Applies the top edge.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field TOP undefined ---@field TOP unknown
-- Applies the right edge. -- Applies the right edge.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field RIGHT undefined ---@field RIGHT unknown
-- Applies the bottom edge. -- Applies the bottom edge.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field BOTTOM undefined ---@field BOTTOM unknown
-- Applies the left edge. -- Applies the left edge.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field LEFT undefined ---@field LEFT unknown
-- Applies all edges. -- Applies all edges.
-- | | | -- | | |
-- | ---- | ----------- | -- | ---- | --------- |
-- | Type | `undefined` | -- | Type | `unknown` |
---@field ALL undefined ---@field ALL unknown
-- You can access all states within [sync context](/docs/plugins/overview#sync-context) through `cx`. -- You can access all states within [sync context](/docs/plugins/overview#sync-context) through `cx`.
@@ -1609,9 +1609,9 @@ ya = ya
-- ``` -- ```
-- | In/Out | Type | -- | In/Out | Type |
-- | --------- | ----------------- | -- | --------- | ----------------- |
-- | Return | `undefined` | -- | Return | `unknown` |
-- | Available | Sync context only | -- | Available | Sync context only |
---@field render fun(): undefined ---@field render fun(): unknown
-- Send a command to the [`[manager]`](/docs/configuration/keymap#manager) without waiting for the executor to execute: -- Send a command to the [`[manager]`](/docs/configuration/keymap#manager) without waiting for the executor to execute:
-- ```lua -- ```lua
-- ya.mgr_emit("my-cmd", { "hello", 123, foo = true, bar_baz = "world" }) -- ya.mgr_emit("my-cmd", { "hello", 123, foo = true, bar_baz = "world" })
@@ -1622,24 +1622,24 @@ ya = ya
-- | ------ | --------------------------------- | --------------------------------------------------------------------------------------- | -- | ------ | --------------------------------- | --------------------------------------------------------------------------------------- |
-- | `cmd` | `string` | - | -- | `cmd` | `string` | - |
-- | `args` | `{ [integer\|string]: Sendable }` | Table values are [Sendable][sendable] that follow [Ownership transfer rules][ownership] | -- | `args` | `{ [integer\|string]: Sendable }` | Table values are [Sendable][sendable] that follow [Ownership transfer rules][ownership] |
-- | Return | `undefined` | - | -- | Return | `unknown` | - |
---@field mgr_emit fun(cmd: string, args: { [integer|string]: Sendable }): undefined ---@field mgr_emit fun(cmd: string, args: { [integer|string]: Sendable }): unknown
-- Display the image of `url` within the `rect`, and the image will downscale to fit the area automatically: -- Display the image of `url` within the `rect`, and the image will downscale to fit the area automatically:
-- | In/Out | Type | -- | In/Out | Type |
-- | --------- | ------------------ | -- | --------- | ------------------ |
-- | `url` | `Url` | -- | `url` | `Url` |
-- | `rect` | `Rect` | -- | `rect` | `Rect` |
-- | Return | `undefined` | -- | Return | `unknown` |
-- | Available | Async context only | -- | Available | Async context only |
---@field image_show fun(url: Url, rect: ui.Rect): undefined ---@field image_show fun(url: Url, rect: ui.Rect): unknown
-- Pre-cache the image of `src` as `dist` based on user-configured [`max_width` and `max_height`](/docs/configuration/yazi#preview). -- Pre-cache the image of `src` as `dist` based on user-configured [`max_width` and `max_height`](/docs/configuration/yazi#preview).
-- | In/Out | Type | -- | In/Out | Type |
-- | --------- | ------------------ | -- | --------- | ------------------ |
-- | `src` | `Url` | -- | `src` | `Url` |
-- | `dist` | `Url` | -- | `dist` | `Url` |
-- | Return | `undefined` | -- | Return | `unknown` |
-- | Available | Async context only | -- | Available | Async context only |
---@field image_precache fun(src: Url, dist: Url): undefined ---@field image_precache fun(src: Url, dist: Url): unknown
-- Prompt users with a set of available keys: -- Prompt users with a set of available keys:
-- ```lua -- ```lua
-- local cand = ya.which { -- local cand = ya.which {
@@ -1729,30 +1729,30 @@ ya = ya
-- | In/Out | Type | -- | In/Out | Type |
-- | ------ | ---------------------------------------------------------------------- | -- | ------ | ---------------------------------------------------------------------- |
-- | `opts` | `{ title: string, content: string, timeout: number?, level: string? }` | -- | `opts` | `{ title: string, content: string, timeout: number?, level: string? }` |
-- | Return | `undefined` | -- | Return | `unknown` |
---@field notify fun(opts: { title: string, content: string, timeout: number?, level: string? }): undefined ---@field notify fun(opts: { title: string, content: string, timeout: number?, level: string? }): unknown
-- Append messages to [the log file](/docs/plugins/overview#logging) at the debug level: -- Append messages to [the log file](/docs/plugins/overview#logging) at the debug level:
-- ```lua -- ```lua
-- ya.dbg("Hello", "World!") -- Multiple arguments are supported -- ya.dbg("Hello", "World!") -- Multiple arguments are supported
-- ya.dbg({ foo = "bar", baz = 123, qux = true }) -- Any type of data is supported -- ya.dbg({ foo = "bar", baz = 123, qux = true }) -- Any type of data is supported
-- ``` -- ```
-- | In/Out | Type | -- | In/Out | Type |
-- | ------ | ----------- | -- | ------ | --------- |
-- | `msg` | `any` | -- | `msg` | `any` |
-- | `...` | `any` | -- | `...` | `any` |
-- | Return | `undefined` | -- | Return | `unknown` |
---@field dbg fun(msg: any, ...: any): undefined ---@field dbg fun(msg: any, ...: any): unknown
-- Append messages to [the log file](/docs/plugins/overview#logging) at the error level: -- Append messages to [the log file](/docs/plugins/overview#logging) at the error level:
-- ```lua -- ```lua
-- ya.err("Hello", "World!") -- Multiple arguments are supported -- ya.err("Hello", "World!") -- Multiple arguments are supported
-- ya.err({ foo = "bar", baz = 123, qux = true }) -- Any type of data is supported -- ya.err({ foo = "bar", baz = 123, qux = true }) -- Any type of data is supported
-- ``` -- ```
-- | In/Out | Type | -- | In/Out | Type |
-- | ------ | ----------- | -- | ------ | --------- |
-- | `msg` | `any` | -- | `msg` | `any` |
-- | `...` | `any` | -- | `...` | `any` |
-- | Return | `undefined` | -- | Return | `unknown` |
---@field err fun(msg: any, ...: any): undefined ---@field err fun(msg: any, ...: any): unknown
-- Preview the file as code into the specified area: -- Preview the file as code into the specified area:
-- ```lua -- ```lua
-- ya.preview_code { -- ya.preview_code {
@@ -1795,9 +1795,9 @@ ya = ya
-- | --------- | --------------------------------------------------------- | -- | --------- | --------------------------------------------------------- |
-- | `opts` | `{ area: Rect, file: File, mime: string, skip: integer }` | -- | `opts` | `{ area: Rect, file: File, mime: string, skip: integer }` |
-- | `widgets` | `Renderable[]` | -- | `widgets` | `Renderable[]` |
-- | Return | `undefined` | -- | Return | `unknown` |
-- | Available | Async context only | -- | Available | Async context only |
---@field preview_widgets fun(opts: { area: ui.Rect, file: File, mime: string, skip: integer }, widgets: Renderable[]): undefined ---@field preview_widgets fun(opts: { area: ui.Rect, file: File, mime: string, skip: integer }, widgets: Renderable[]): unknown
-- See [Async context](/docs/plugins/overview#async-context). -- See [Async context](/docs/plugins/overview#async-context).
-- | In/Out | Type | -- | In/Out | Type |
-- | ------ | -------------------- | -- | ------ | -------------------- |
@@ -1875,9 +1875,9 @@ ya = ya
-- | In/Out | Type | -- | In/Out | Type |
-- | --------- | ------------------ | -- | --------- | ------------------ |
-- | `secs` | `number` | -- | `secs` | `number` |
-- | Return | `undefined` | -- | Return | `unknown` |
-- | Available | Async context only | -- | Available | Async context only |
---@field sleep fun(secs: number): undefined ---@field sleep fun(secs: number): unknown
-- Returns the id of the current user. -- Returns the id of the current user.
-- | In/Out | Type | -- | In/Out | Type |
-- | --------- | ---------------------- | -- | --------- | ---------------------- |
@@ -1932,12 +1932,12 @@ ya = ya
-- ``` -- ```
-- Since the `kind` is used globally, to add the plugin name as the prefix is a best practice. -- Since the `kind` is used globally, to add the plugin name as the prefix is a best practice.
-- For example, the combination of the plugin `my-plugin` and the kind `event1` would be `my-plugin-event1`. -- For example, the combination of the plugin `my-plugin` and the kind `event1` would be `my-plugin-event1`.
-- | In/Out | Type | Note | -- | In/Out | Type | Note |
-- | ------- | ----------- | ------------------------------------------------------------------------------- | -- | ------- | ---------- | ------------------------------------------------------------------------------- |
-- | `kind` | `string` | Alphanumeric with dashes, cannot be [built-in kinds](/docs/dds#kinds) | -- | `kind` | `string` | Alphanumeric with dashes, cannot be [built-in kinds](/docs/dds#kinds) |
-- | `value` | `Sendable` | A [Sendable value][sendable] that follows [Ownership transfer rules][ownership] | -- | `value` | `Sendable` | A [Sendable value][sendable] that follows [Ownership transfer rules][ownership] |
-- | Return | `undefined` | - | -- | Return | `unknown` | - |
---@field pub fun(kind: string, value: Sendable): undefined ---@field pub fun(kind: string, value: Sendable): unknown
-- Publish a message to a specific instance with `receiver` as the ID: -- Publish a message to a specific instance with `receiver` as the ID:
-- ```lua -- ```lua
-- ps.pub_to(1711957283332834, "greeting", "Hello, World!") -- ps.pub_to(1711957283332834, "greeting", "Hello, World!")
@@ -1946,13 +1946,13 @@ ya = ya
-- - Local - `receiver` is the current instance, and is subscribed to this `kind` via `sub()`, it will receive the message. -- - Local - `receiver` is the current instance, and is subscribed to this `kind` via `sub()`, it will receive the message.
-- - Remote - `receiver` isn't the current instance, and is subscribed to this `kind` via `sub_remote()`, it will receive the message. -- - Remote - `receiver` isn't the current instance, and is subscribed to this `kind` via `sub_remote()`, it will receive the message.
-- - Broadcast - `receiver` is `0`, all remote instances subscribed to this `kind` via `sub_remote()` will receive the message. -- - Broadcast - `receiver` is `0`, all remote instances subscribed to this `kind` via `sub_remote()` will receive the message.
-- | In/Out | Type | Note | -- | In/Out | Type | Note |
-- | ---------- | ----------- | ------------------------------------------------------------------------------- | -- | ---------- | ---------- | ------------------------------------------------------------------------------- |
-- | `receiver` | `integer` | - | -- | `receiver` | `integer` | - |
-- | `kind` | `string` | Alphanumeric with dashes, cannot be [built-in kinds](/docs/dds#kinds) | -- | `kind` | `string` | Alphanumeric with dashes, cannot be [built-in kinds](/docs/dds#kinds) |
-- | `value` | `Sendable` | A [Sendable value][sendable] that follows [Ownership transfer rules][ownership] | -- | `value` | `Sendable` | A [Sendable value][sendable] that follows [Ownership transfer rules][ownership] |
-- | Return | `undefined` | - | -- | Return | `unknown` | - |
---@field pub_to fun(receiver: integer, kind: string, value: Sendable): undefined ---@field pub_to fun(receiver: integer, kind: string, value: Sendable): unknown
-- Subscribe to local messages of `kind` and call the `callback` handler for it: -- Subscribe to local messages of `kind` and call the `callback` handler for it:
-- ```lua -- ```lua
-- -- The same `kind` from the same plugin can only be subscribed once, -- -- The same `kind` from the same plugin can only be subscribed once,
@@ -1966,33 +1966,33 @@ ya = ya
-- | ---------- | --------------------- | --------------------------------------------------------------------- | -- | ---------- | --------------------- | --------------------------------------------------------------------- |
-- | `kind` | `string` | Alphanumeric with dashes, cannot be [built-in kinds](/docs/dds#kinds) | -- | `kind` | `string` | Alphanumeric with dashes, cannot be [built-in kinds](/docs/dds#kinds) |
-- | `callback` | `fun(body: Sendable)` | No time-consuming work should be done in the callback | -- | `callback` | `fun(body: Sendable)` | No time-consuming work should be done in the callback |
-- | Return | `undefined` | - | -- | Return | `unknown` | - |
---@field sub fun(kind: string, callback: fun(body: Sendable)): undefined ---@field sub fun(kind: string, callback: fun(body: Sendable)): unknown
-- Same as `sub()`, except it subscribes to remote messages of this `kind` instead of local. -- Same as `sub()`, except it subscribes to remote messages of this `kind` instead of local.
-- | In/Out | Type | Note | -- | In/Out | Type | Note |
-- | ---------- | --------------------- | --------------- | -- | ---------- | --------------------- | --------------- |
-- | `kind` | `string` | Same as `sub()` | -- | `kind` | `string` | Same as `sub()` |
-- | `callback` | `fun(body: Sendable)` | Same as `sub()` | -- | `callback` | `fun(body: Sendable)` | Same as `sub()` |
-- | Return | `undefined` | - | -- | Return | `unknown` | - |
---@field sub_remote fun(kind: string, callback: fun(body: Sendable)): undefined ---@field sub_remote fun(kind: string, callback: fun(body: Sendable)): unknown
-- Unsubscribe from local messages of this `kind`: -- Unsubscribe from local messages of this `kind`:
-- ```lua -- ```lua
-- ps.unsub("my-message") -- ps.unsub("my-message")
-- ``` -- ```
-- | In/Out | Type | Note | -- | In/Out | Type | Note |
-- | ------ | ----------- | --------------------------------------------------------------------- | -- | ------ | --------- | --------------------------------------------------------------------- |
-- | `kind` | `string` | Alphanumeric with dashes, cannot be [built-in kinds](/docs/dds#kinds) | -- | `kind` | `string` | Alphanumeric with dashes, cannot be [built-in kinds](/docs/dds#kinds) |
-- | Return | `undefined` | - | -- | Return | `unknown` | - |
---@field unsub fun(kind: string): undefined ---@field unsub fun(kind: string): unknown
-- Unsubscribe from remote messages of this `kind`: -- Unsubscribe from remote messages of this `kind`:
-- ```lua -- ```lua
-- ps.unsub_remote("my-message") -- ps.unsub_remote("my-message")
-- ``` -- ```
-- | In/Out | Type | Note | -- | In/Out | Type | Note |
-- | ------ | ----------- | ----------------- | -- | ------ | --------- | ----------------- |
-- | `kind` | `string` | Same as `unsub()` | -- | `kind` | `string` | Same as `unsub()` |
-- | Return | `undefined` | - | -- | Return | `unknown` | - |
---@field unsub_remote fun(kind: string): undefined ---@field unsub_remote fun(kind: string): unknown
-- The following functions can only be used within an async context. -- The following functions can only be used within an async context.
---@class (exact) fs ---@class (exact) fs
@@ -2371,6 +2371,12 @@ ya = ya
---@class (exact) ui ---@class (exact) ui
-- --
---@field Constraint ui.Constraint ---@field Constraint ui.Constraint
--
---@field Align ui.Align
--
---@field Wrap ui.Wrap
--
---@field Edge ui.Edge
-- Make a new rect. -- Make a new rect.
-- | In/Out | Type | -- | In/Out | Type |
-- | ------- | -------------------------------------------------------- | -- | ------- | -------------------------------------------------------- |
@@ -2431,7 +2437,7 @@ ya = ya
-- | ------ | --------------- | -- | ------ | --------------- |
-- | `edge` | [`Edge`](#edge) | -- | `edge` | [`Edge`](#edge) |
-- | Return | `Self` | -- | Return | `Self` |
---@field Border fun(edge: Edge): ui.Border ---@field Border fun(edge: ui.Edge): ui.Border
-- Make a new gauge. -- Make a new gauge.
-- | In/Out | Type | -- | In/Out | Type |
-- | ------ | ------ | -- | ------ | ------ |