gitdiff-parser
gitdiff-parser copied to clipboard
Fix types
The type export is malformed and gives errors in current versions of typescript
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
.