TS2740

error TS2740: Type ‘TextLine‘ is missing the following properties from type ‘Position‘: line, character, isBefore, isBeforeOrEqual, and 6 more.

Broken Code ❌

1
2
3
4
5
6
7
import {Position, TextEditor} from 'vscode';

function logPosition(textEditor: TextEditor,
startLine: Position = textEditor.document.lineAt(0)
) {
console.log(startLine.line);
}

Fixed Code ✔️

The parameter startLine is requiring a value of type Position but the default value returns a value of type TextLine, so this has to be fixed to return the expected type:

1
2
3
4
5
6
7
import {Position, TextEditor} from 'vscode';

function logPosition(textEditor: TextEditor,
startLine: Position = textEditor.document.lineAt(0).range.start
) {
console.log(startLine.line);
}