Skip to content

Commit 9342b5a

Browse files
committed
fix: make edit param required in CommandRegistration interface.
- Reverted the `edit` param in the `handleSingleLineBlock` Configuration method back to be required instead of optional because it otherwise insinuates the method can work without the `edit` param which is not true. It must have the param set to work. Also removed the optional chaining operator on the `edit.insert` call. The TS error that the optional operators fixed will return: "Type '(textEditor: TextEditor, edit: TextEditorEdit) => void' is not assignable to type '(textEditor: TextEditor, edit?: TextEditorEdit | undefined) => void'. Types of parameters 'edit' and 'edit' are incompatible. Type 'TextEditorEdit | undefined' is not assignable to type 'TextEditorEdit'. Type 'undefined' is not assignable to type 'TextEditorEdit'." - Fixed the returning TS error above by making the `edit` param required instead of optional in the `handler` function in `CommandRegistration` interface, which the `handleSingleLineBlock` method has to satisfy.
1 parent 276724d commit 9342b5a

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ export class Configuration {
939939
* @param {vscode.TextEditor} textEditor The text editor.
940940
* @param {vscode.TextEditorEdit} edit The text editor edits.
941941
*/
942-
private handleSingleLineBlock(textEditor: vscode.TextEditor, edit?: vscode.TextEditorEdit) {
942+
private handleSingleLineBlock(textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) {
943943
let langId: LanguageId = textEditor.document.languageId;
944944
const singleLineLangs = this.getSingleLineLanguages("supportedLanguages");
945945
const customSingleLineLangs = this.getSingleLineLanguages("customSupportedLanguages");
@@ -988,7 +988,7 @@ export class Configuration {
988988
indentedNewLine += style + " ";
989989
}
990990

991-
edit?.insert(textEditor.selection.active, indentedNewLine);
991+
edit.insert(textEditor.selection.active, indentedNewLine);
992992
}
993993
}
994994

src/interfaces/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export interface CommandRegistration {
1818
* command is executed.
1919
*
2020
* @param textEditor The text editor
21-
* @param edit The text editor edits. Optional because some commands may not need it.
21+
* @param edit The text editor edits.
2222
* @returns void
2323
*/
24-
handler: (textEditor: vscode.TextEditor, edit?: vscode.TextEditorEdit) => void;
24+
handler: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) => void;
2525
}
2626

2727
/**

0 commit comments

Comments
 (0)