gitdiff-parser icon indicating copy to clipboard operation
gitdiff-parser copied to clipboard

Fix types

Open oBusk opened this issue 2 years ago • 2 comments

The type export is malformed and gives errors in current versions of typescript

image

node_modules/gitdiff-parser/index.d.ts(36,16): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
node_modules/gitdiff-parser/index.d.ts(37,34): error TS1005: '{' expected.

This also does not work if you want to use gitDiffParser globally (not importing). Since the index.js exports as a UMD, I followed the example https://devblogs.microsoft.com/typescript/writing-dts-files-for-types/

With this type, all the following works

// Reference for `<script>`-imported library
/// <reference path="gitdiff-parser" />

gitDiffParser.parse(gitContent);
import { parse } from "gitdiff-parser";

parse(gitContent);
import gitDiffParser from "gitdiff-parser";

gitDiffParser.parse(gitContent);

As a bonus I added exports for FileType and ChangeType.

oBusk avatar Jun 22 '22 22:06 oBusk