Skip to content

Commit ed141d1

Browse files
author
Taras Mankovski
committed
Fix type annotations for npm packages in Deno
- Add explicit type imports for node:http (IncomingMessage, ServerResponse) - Add custom FSWatcherWithEvents interface to properly type chokidar watcher with EventEmitter methods that aren't exposed in the base type These explicit types ensure consistent type checking across different Deno environments and caching states.
1 parent b1a80ab commit ed141d1

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

fx/request.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ import { beforeEach, describe, it } from "@effectionx/bdd";
22
import { expect } from "@std/expect";
33

44
import { call, ensure, withResolvers } from "effection";
5-
import { createServer } from "node:http";
5+
import {
6+
createServer,
7+
type IncomingMessage,
8+
type ServerResponse,
9+
} from "node:http";
610
import { json, request } from "./request.ts";
711

812
// Ensure to run tests with --allow-net permission
913
describe("request() and json()", () => {
1014
let url: string;
1115
beforeEach(function* () {
12-
let server = createServer((_req, res) => {
13-
res.writeHead(200, { "Content-Type": "application/json" });
14-
res.end(JSON.stringify({ id: 1, title: "do things" }));
15-
});
16+
let server = createServer(
17+
(_req: IncomingMessage, res: ServerResponse) => {
18+
res.writeHead(200, { "Content-Type": "application/json" });
19+
res.end(JSON.stringify({ id: 1, title: "do things" }));
20+
},
21+
);
1622

1723
const ready = withResolvers<void>();
1824
server.listen(0, () => ready.resolve());

watch/watch.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import { exec, type ExecOptions, type Process } from "@effectionx/process";
2222

2323
import { debounce } from "./stream-helpers.ts";
2424

25+
// Extended FSWatcher interface that includes EventEmitter methods
26+
interface FSWatcherWithEvents {
27+
on(event: string, listener: (...args: EmitArgsWithName) => void): this;
28+
close(): Promise<void>;
29+
}
30+
2531
/**
2632
* Represents a single start of the specified command
2733
*/
@@ -105,14 +111,16 @@ export function watch(options: WatchOptions): Stream<Start, never> {
105111

106112
let gitignored = yield* findIgnores(options.path);
107113

114+
// Cast to extended interface that includes EventEmitter methods
108115
let watcher = chokidar.watch(options.path, {
109116
ignored: (path) => {
110117
let relpath = relative(options.path, path);
111118
let isGit = relpath === ".git" || relpath.startsWith(".git");
112119
return isGit || gitignored(path);
113120
},
114121
ignoreInitial: true,
115-
});
122+
}) as unknown as FSWatcherWithEvents;
123+
116124
let { event = "all" } = options;
117125
watcher.on(event, (...args: EmitArgsWithName) => {
118126
if (event !== "all") {

0 commit comments

Comments
 (0)