Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @import {FSWatcher} from 'chokidar'
* @import {Options} from 'unified-args'
* @import {Callback as EngineCallback, Context as EngineContext} from 'unified-engine'
* @import {State} from './parse-argv.js'
Expand Down Expand Up @@ -35,7 +36,7 @@ process.on('uncaughtException', fail)
export function args(options) {
/** @type {State} */
let state
/** @type {chokidar.FSWatcher | undefined} */
/** @type {FSWatcher | undefined} */
let watcher
/** @type {URL | boolean | string | undefined} */
let output
Expand Down Expand Up @@ -150,7 +151,8 @@ export function args(options) {
// `cwd` can be `undefined`.
{cwd, ignoreInitial: true}
)
.on('error', done)
// Cast: chokidar passes `unknown`, we know it’s an error.
.on('error', /** @type {(error: unknown) => undefined} */ (done))
.on('change', function (filePath) {
state.engine.files = [filePath]
engine(state.engine, done)
Expand Down
10 changes: 6 additions & 4 deletions lib/parse-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ function parseIfString(value) {
* Value, or the last item of it if it’s an array.
*/
function lastIfArray(value) {
// @ts-expect-error: this is good.
return Array.isArray(value) ? value[value.length - 1] : value
}

Expand All @@ -478,10 +479,11 @@ function joinIfArray(value) {
* Value, or an array of it if it’s a non-nully primitive.
*/
function toArray(value) {
// @ts-expect-error: this is good.
return Array.isArray(value) || value === null || value === undefined
? value
: [value]
return /** @type {T extends boolean | number | string ? Array<T> : T} */ (
Array.isArray(value) || value === null || value === undefined
? value
: [value]
)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"@types/text-table": "^0.2.0",
"chalk": "^5.0.0",
"chokidar": "^3.0.0",
"chokidar": "^5.0.0",
"comma-separated-tokens": "^2.0.0",
"json5": "^2.0.0",
"minimist": "^1.0.0",
Expand Down
Loading