diff --git a/src/core/documents.ts b/src/core/documents.ts index 92ff773b4f3..1b1d6721a9d 100644 --- a/src/core/documents.ts +++ b/src/core/documents.ts @@ -186,7 +186,7 @@ export default class Documents implements Disposable { return docs } - public getDocument(uri: number | string, caseInsensitive = platform.isWindows || platform.isMacintosh): Document | null { + public getDocument(uri: number | string, caseInsensitive = platform.isWindows || platform.isMacintosh): Document | null | undefined { if (typeof uri === 'number') { return this.buffers.get(uri) } diff --git a/src/workspace.ts b/src/workspace.ts index 0d697f5efac..61d9adf60d6 100644 --- a/src/workspace.ts +++ b/src/workspace.ts @@ -357,13 +357,13 @@ export class Workspace { /** * Get created document by uri or bufnr. */ - public getDocument(uri: number | string): Document | null { + public getDocument(uri: number | string): Document | null | undefined { return this.documentsManager.getDocument(uri) } public hasDocument(uri: string, version?: number): boolean { let doc = this.documentsManager.getDocument(uri) - return doc != null && (version != null ? doc.version == version : true) + return doc && (version != null ? doc.version == version : true) } public getUri(bufnr: number, defaultValue = ''): string { diff --git a/typings/index.d.ts b/typings/index.d.ts index 81a37bc8adf..143011e2353 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -8934,7 +8934,7 @@ declare module 'coc.nvim' { /** * Get created document by uri or bufnr. */ - export function getDocument(uri: number | string): Document + export function getDocument(uri: number | string): Document | null | undefined /** * Apply WorkspaceEdit.