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

Fix types

Open oBusk opened this issue 3 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

Any update here? Am running into the same compilation warnings on [email protected]

ciaran1344 avatar Jan 05 '23 18:01 ciaran1344

There was some improvements to the type surrounding the ChangeType and FileType, but the default export is still the same, so I've rebased this PR let's see if we can get it in 😄

oBusk avatar Apr 12 '23 16:04 oBusk