Skip to content

Commit 437763e

Browse files
Jakob Schlanstedtwerererer
authored andcommitted
fix(type-checker): remove as casts hiding type-errors thus bugs. Solve subsequent found bugs
1 parent 3d3d112 commit 437763e

File tree

13 files changed

+76
-44
lines changed

13 files changed

+76
-44
lines changed

apps/client/src/components/entrypoints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class Entrypoints extends Component {
2626

2727
async createNoteIntoInboxCommand() {
2828
await noteCreateService.createNote(
29-
{ target: "inbox" } as CreateNoteIntoInboxOpts
29+
{ target: "inbox" }
3030
);
3131
}
3232

apps/client/src/components/main_tree_executors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class MainTreeExecutors extends Component {
5555
isProtected: activeNoteContext.note.isProtected,
5656
saveSelection: false,
5757
promptForType: false,
58-
} as CreateNoteWithUrlOpts
58+
}
5959
);
6060
}
6161

@@ -84,7 +84,7 @@ export default class MainTreeExecutors extends Component {
8484
targetBranchId: node.data.branchId,
8585
isProtected: isProtected,
8686
saveSelection: false
87-
} as CreateNoteWithUrlOpts
87+
}
8888
);
8989
}
9090
}

apps/client/src/components/root_command_executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export default class RootCommandExecutor extends Component {
243243
messages: [],
244244
title: "New AI Chat"
245245
}),
246-
} as CreateNoteWithUrlOpts
246+
}
247247
);
248248

249249
if (!result.note) {

apps/client/src/menus/tree_context_menu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
283283
isProtected: isProtected,
284284
templateNoteId: templateNoteId,
285285
promptForType: false,
286-
} as CreateNoteWithUrlOpts
286+
}
287287
);
288288
} else if (command === "insertChildNote") {
289289
const parentNotePath = treeService.getNotePath(this.node);
@@ -296,7 +296,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
296296
isProtected: this.node.data.isProtected,
297297
templateNoteId: templateNoteId,
298298
promptForType: false,
299-
} as CreateNoteWithUrlOpts
299+
}
300300
);
301301
} else if (command === "openNoteInSplit") {
302302
const subContexts = appContext.tabManager.getActiveContext()?.getSubContexts();

apps/client/src/services/note_create.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ type PromptingRule = {
4848
type?: never;
4949
} | {
5050
promptForType?: false;
51-
type: string;
51+
/**
52+
* The note type (e.g. "text", "code", "image", "mermaid", etc.).
53+
*
54+
* If omitted, the server will automatically default to `"text"`.
55+
* TypeScript still enforces explicit typing unless `promptForType` is true,
56+
* to encourage clarity at the call site.
57+
*/
58+
type?: string;
5259
};
5360

5461

@@ -120,16 +127,15 @@ async function createNote(
120127
resolvedOptions = maybeResolvedOptions;
121128
}
122129

123-
if (resolvedOptions.target === "inbox") {
124-
return createNoteIntoInbox(resolvedOptions);
125-
}
126130

127-
// Only "into" | "before" | "after". the possibility of "inbox" was resolved
128-
// a line above
129-
return createNoteWithUrl(
130-
resolvedOptions.target as "into" | "before" | "after",
131-
resolvedOptions
132-
);
131+
switch(resolvedOptions.target) {
132+
case "inbox":
133+
return createNoteIntoInbox(resolvedOptions);
134+
case "into":
135+
case "before":
136+
case "after":
137+
return createNoteWithUrl(resolvedOptions.target, resolvedOptions);
138+
}
133139
}
134140

135141
async function promptForType(
@@ -141,20 +147,20 @@ async function promptForType(
141147
return null;
142148
}
143149

144-
let resolvedOptions = {
150+
let resolvedOptions: CreateNoteOpts = {
145151
...options,
146152
promptForType: false,
147153
type: noteType,
148154
templateNoteId,
149-
} as CreateNoteOpts;
155+
};
150156

151157
if (notePath) {
152158
resolvedOptions = resolvedOptions as CreateNoteWithUrlOpts;
153159
resolvedOptions = {
154160
...resolvedOptions,
155161
target: "into",
156162
parentNoteUrl: notePath,
157-
} as CreateNoteWithUrlOpts;
163+
};
158164
}
159165

160166
return resolvedOptions;
@@ -269,7 +275,7 @@ async function createNoteIntoInbox(
269275
...options,
270276
target: "into",
271277
parentNoteUrl: inboxNote.noteId,
272-
} as CreateNoteWithUrlOpts
278+
}
273279
);
274280

275281
return result;

apps/client/src/widgets/collections/board/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class BoardApi {
3333
parentNoteUrl: parentNotePath,
3434
activate: false,
3535
title,
36-
} as CreateNoteWithUrlOpts);
36+
});
3737

3838
if (newNote && newBranch) {
3939
await this.changeColumn(newNote.noteId, column);
@@ -140,7 +140,7 @@ export default class BoardApi {
140140
activate: false,
141141
targetBranchId: relativeToBranchId,
142142
title: t("board_view.new-item"),
143-
} as CreateNoteWithUrlOpts
143+
}
144144
);
145145

146146
if (!note || !branch) {

apps/client/src/widgets/collections/table/context_menu.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
183183
handler: () => parentComponent?.triggerCommand("addNewRow", {
184184
parentNotePath: parentNoteId,
185185
customOpts: {
186+
parentNoteUrl: parentNoteId,
186187
target: "before",
187188
targetBranchId: rowData.branchId,
188-
} as CreateNoteWithUrlOpts
189+
}
189190
})
190191
},
191192
{
@@ -194,12 +195,16 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
194195
handler: async () => {
195196
const branchId = row.getData().branchId;
196197
const note = await froca.getBranch(branchId)?.getNote();
198+
if (!note) {
199+
return;
200+
}
197201
parentComponent?.triggerCommand("addNewRow", {
198-
parentNotePath: note?.noteId,
202+
parentNotePath: note.noteId,
199203
customOpts: {
204+
parentNoteUrl: note.noteId,
200205
target: "after",
201206
targetBranchId: branchId,
202-
} as CreateNoteWithUrlOpts
207+
}
203208
});
204209
}
205210
},
@@ -210,9 +215,10 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
210215
handler: () => parentComponent?.triggerCommand("addNewRow", {
211216
parentNotePath: parentNoteId,
212217
customOpts: {
218+
parentNoteUrl: parentNoteId,
213219
target: "after",
214220
targetBranchId: rowData.branchId,
215-
} as CreateNoteWithUrlOpts
221+
}
216222
})
217223
},
218224
{ kind: "separator" },

apps/client/src/widgets/collections/table/row_editing.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ export default function useRowTableEditing(api: RefObject<Tabulator>, attributeD
1919
activate: false,
2020
...customOpts
2121
}
22+
23+
// Normalize "inbox" targets into standard path-based creation.
24+
// When adding a new row, we always have a concrete parent path (`notePath`),
25+
// so even if the originating command requested an "inbox" creation,
26+
// it should instead behave as "into" under the current note.
27+
const normalizedOpts: CreateNoteWithUrlOpts =
28+
opts.target === "inbox"
29+
? { ...opts, target: "into", parentNoteUrl: notePath }
30+
: { ...opts, parentNoteUrl: notePath };
31+
2232
note_create.createNote(
23-
{
24-
parentNoteUrl: notePath,
25-
...opts
26-
} as CreateNoteWithUrlOpts
33+
normalizedOpts
2734
).then(({ branch }) => {
2835
if (branch) {
2936
setTimeout(() => {

apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ export default function MobileDetailMenu() {
2929
],
3030
selectMenuItemHandler: async ({ command }) => {
3131
if (command === "insertChildNote") {
32-
note_create.createNote(
33-
{
32+
const parentNoteUrl = appContext.tabManager.getActiveContextNotePath();
33+
34+
if (parentNoteUrl) {
35+
note_create.createNote({
3436
target: "into",
35-
parentNoteUrl: appContext.tabManager.getActiveContextNotePath() ?? undefined
36-
} as CreateNoteWithUrlOpts
37-
);
37+
parentNoteUrl,
38+
});
39+
}
3840
} else if (command === "delete") {
3941
const notePath = appContext.tabManager.getActiveContextNotePath();
4042
if (!notePath) {

apps/client/src/widgets/note_detail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
436436
isProtected: note.isProtected,
437437
saveSelection: true,
438438
textEditor: await this.noteContext.getTextEditor()
439-
} as CreateNoteWithUrlOpts
439+
}
440440
);
441441
}
442442
}

0 commit comments

Comments
 (0)