Skip to content
Merged
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
11 changes: 6 additions & 5 deletions src/livecodes/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1969,11 +1969,12 @@ const loadSelectedScreen = () => {
return false;
};

const getAllEditors = (): CodeEditor[] => [
...Object.values(editors),
...[toolsPane?.console?.getEditor?.()],
...[toolsPane?.compiled?.getEditor?.()],
];
const getAllEditors = (): CodeEditor[] =>
[
...Object.values(editors),
toolsPane?.console?.getEditor?.(),
toolsPane?.compiled?.getEditor?.(),
].filter((x) => x != null);
Comment on lines +1972 to +1977
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Use a proper type guard in the filter.

The filter((x) => x != null) call still yields (CodeEditor | undefined)[], so the function body is not assignable to the declared CodeEditor[] return type and fails TypeScript’s strict checking. Please tighten the predicate to narrow the type before returning.

-  ].filter((x) => x != null);
+  ].filter((x): x is CodeEditor => x != null);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const getAllEditors = (): CodeEditor[] =>
[
...Object.values(editors),
toolsPane?.console?.getEditor?.(),
toolsPane?.compiled?.getEditor?.(),
].filter((x) => x != null);
const getAllEditors = (): CodeEditor[] =>
[
...Object.values(editors),
toolsPane?.console?.getEditor?.(),
toolsPane?.compiled?.getEditor?.(),
].filter((x): x is CodeEditor => x != null);
🤖 Prompt for AI Agents
In src/livecodes/core.ts around lines 1972-1977, the array filter currently uses
filter((x) => x != null) which does not narrow the type to CodeEditor[]; replace
that predicate with a proper TypeScript type guard such as filter((x): x is
CodeEditor => x != null) (or an equivalent type-predicate function) so the
result is correctly inferred as CodeEditor[] and satisfies strict checking.


const setTheme = (theme: Theme, editorTheme: Config['editorTheme']) => {
const themes = ['light', 'dark'];
Expand Down
1 change: 1 addition & 0 deletions src/livecodes/editor/monaco/monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export const createEditor = async (options: EditorOptions): Promise<CodeEditor>
glyphMargin: true,
folding: false,
lineDecorationsWidth: 0,
lineNumbers: 'off',
lineNumbersMinChars: 0,
scrollbar: {
vertical: 'auto',
Expand Down