8000 Incorrect types for `diffJson` · Issue #609 · kpdecker/jsdiff · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Incorrect types for diffJson #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joshkel opened this issue May 13, 2025 · 1 comment · Fixed by #610
Closed

Incorrect types for diffJson #609

joshkel opened this issue May 13, 2025 · 1 comment · Fixed by #610

Comments

@joshkel
Copy link
Contributor
joshkel commented May 13, 2025

@types/diff gave the following types for diffJson:

export function diffJson(
    oldObj: string | object,
    newObj: string | object,
    options?: JsonOptions,
): Change[];
export function diffJson(
    oldObj: string | object,
    newObj: string | object,
    options: Callback<Change[]> | (JsonOptions & CallbackOptions<Change[]>),
): void;

And, since diffJson serializes to JSON itself, these types appear to be correct. However, diff v8 requires string inputs:

export declare function diffJson(oldStr: string, newStr: string, options: DiffCallbackNonabortable<string>): undefined;
export declare function diffJson(oldStr: string, newStr: string, options: DiffJsonOptionsAbortable & CallbackOptionAbortable<string>): undefined;
export declare function diffJson(oldStr: string, newStr: string, options: DiffJsonOptionsNonabortable & CallbackOptionNonabortable<string>): undefined;
export declare function diffJson(oldStr: string, newStr: string, options: DiffJsonOptionsAbortable): ChangeObject<string>[] | undefined;
export declare function diffJson(oldStr: string, newStr: string, options?: DiffJsonOptionsNonabortable): ChangeObject<string>[];
@ExplodingCabbage
Copy link
Collaborator

D'oh. Yeah, that's definitely wrong. Thanks for catching. Will fix right now.

Probably I should've ported the whole test suite to TypeScript to catch bugs like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0