Skip to content

Commit aa3d525

Browse files
fix: resolve TypeScript errors in documentation examples and improve type handling
- Add null checks in documentation examples for getTweetInfo and link - Fix signal variable name in WebSocket listen example - Improve type handling in pin.ts changes array - Update type annotations in documentation examples
1 parent a003b14 commit aa3d525

File tree

8 files changed

+24
-15
lines changed

8 files changed

+24
-15
lines changed

browser/dom/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* This function searches through the cache storage in reverse chronological order
44
* to find the most recent cached response for a given request.
5-
*
5+
*
66
* > [!Note]
77
* > Implementation inspired by Scrapbox's ServiceWorker and Cache usage pattern.
88
*

browser/dom/caret.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { textInput } from "./dom.ts";
22

33
/** Position information within the editor
4-
*
4+
*
55
* @see {@linkcode Range} for selection range information
66
*/
77
export interface Position {
@@ -12,7 +12,7 @@ export interface Position {
1212
/** Represents a text selection range in the editor
1313
*
1414
* When no text is selected, {@linkcode start} and {@linkcode end} positions are the same (cursor position)
15-
*
15+
*
1616
* @see {@linkcode Position} for position type details
1717
*/
1818
export interface Range {

browser/dom/cursor.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface SetPositionOptions {
1717
}
1818

1919
/** Class for managing cursor operations in the Scrapbox editor
20-
*
20+
*
2121
* @see {@linkcode Position} for cursor position type details
2222
* @see {@linkcode Page} for page data type details
2323
*/

browser/websocket/findMetadata.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ Prepare thumbnail
4242
Deno.test({
4343
name: "findMetadata()",
4444
ignore: true,
45-
fn: (t) => assertSnapshot(t, findMetadata(text))
45+
fn: (t) => assertSnapshot(t, findMetadata(text)),
4646
});
4747

4848
// Test Helpfeel extraction (lines starting with "?")
4949
// These are used for collecting questions and help requests in Scrapbox
5050
Deno.test({
5151
name: "getHelpfeels()",
5252
ignore: true,
53-
fn: () =>
54-
assertEquals(getHelpfeels(text.split("\n").map((text) => ({ text }))), [
55-
"Help needed with setup!!",
56-
]));
53+
fn: () => {
54+
assertEquals(getHelpfeels(text.split("\n").map((text) => ({ text }))), [
55+
"Help needed with setup!!",
56+
]);
57+
},
58+
});

browser/websocket/listen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export type ListenStreamError =
4242
*
4343
* Example:
4444
* ```ts
45-
* listen(socket, "project:update", (data) => {
45+
* listen(socket, "project:update", (data: ProjectUpdateData) => {
4646
* console.log("Project updated:", data);
47-
* }, { signal: abortController.signal });
47+
* }, { signal: controller.signal });
4848
* ```
4949
*/
5050
export const listen = <EventName extends keyof ListenEvents>(

browser/websocket/pin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export const pin = (
4343
) return [];
4444
// Create page and pin it in a single operation
4545
// Note: The server accepts combined creation and pin operations
46-
const changes: Change[] = [{ pin: pinNumber() }] as Change[];
46+
const pinChange: Change = { pin: pinNumber() };
47+
const changes: Change[] = [pinChange];
4748
if (!page.persistent) changes.unshift({ title });
4849
return changes;
4950
},

rest/getTweetInfo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export type TweetInfoError =
5151
* return;
5252
* }
5353
* const tweetInfo = result.val;
54-
* console.log("Tweet text:", tweetInfo.text);
54+
* if (tweetInfo) {
55+
* console.log("Tweet text:", tweetInfo.text);
56+
* }
5557
* ```
5658
*
5759
* Note: The function includes a 3000ms timeout for the API request.

rest/link.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ export const getLinks: GetLinks = /* @__PURE__ */ (() => {
170170
* break;
171171
* }
172172
* const links = result.val; // Array of links in this batch
173-
* console.log(`Got ${links.length} links`);
173+
* if (links) {
174+
* console.log(`Got ${links.length} links`);
175+
* }
174176
* }
175177
* ```
176178
*/
@@ -216,7 +218,9 @@ export async function* readLinksBulk(
216218
* break;
217219
* }
218220
* const link = result.val; // Single link entry
219-
* console.log("Processing link:", link.title);
221+
* if (link) {
222+
* console.log("Processing link:", link.title);
223+
* }
220224
* }
221225
* ```
222226
*/

0 commit comments

Comments
 (0)