epoberezkin / fast-json-stable-stringify

Deterministic JSON.stringify() - a faster version of @substack's json-stable-strigify without jsonify.
Other
285 stars 34 forks source link

Update Typescript declaration file to use standard export syntax. #15

Open vedantroy opened 4 years ago

vedantroy commented 4 years ago

The current index.d.ts file looks like this:

declare module 'fast-json-stable-stringify' {
  function stringify(obj: any): string;
  export = stringify;
}

This makes it impossible to use this module from Typescript unless a certain flag is turned on (I forget the flag name) because this syntax is outdated.

I recommend updating the index.d.ts file to:

export default function stringify(obj: any): string

Not sure if that's correct, but I think it is?

stasyuk93 commented 4 years ago

type should be

declare function stringify(obj: any, options?: stringify.Options | stringify.Comparator): string;

declare namespace stringify {
    interface Options {
        cmp?: (a: CompareDescriptor, b: CompareDescriptor) => number;
        cycles?: boolean;
    }

    type Comparator = (a: CompareDescriptor, b: CompareDescriptor) => number;

    interface CompareDescriptor {
        key: string;
        value: any;
    }
}