Skip to content
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

Add: typings #7

Merged
merged 1 commit into from Sep 13, 2021
Merged

Add: typings #7

merged 1 commit into from Sep 13, 2021

Conversation

lexich
Copy link
Contributor

@lexich lexich commented Sep 13, 2021

No description provided.

index.d.ts Outdated

export function stringifyInfo(
value: any,
replacer?: ((this: any, key: string, value: any) => any) | undefined,
Copy link
Member

@smelukov smelukov Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a field is optional foo?: then there is no need | undefined
here and below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just only copy typing from JSON.stringify. Fixed

index.d.ts Outdated

export function parseChunked<T>(stream: Readable | Generator<any, void, unknown>): Promise<T>;

export function stringifyStream(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): Readable;
Copy link
Member

@smelukov smelukov Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move replacer function into a separate type to make code more clearer )

Copy link
Member

@lahmatiy lahmatiy Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.d.ts Outdated
continueOnCircular?: boolean;
}
): {
minLength: Number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number for consistency

index.d.ts Outdated
declare module '@discoveryjs/json-ext' {
import { Readable } from 'stream';

export function parseChunked<T>(stream: Readable | Generator<any, void, unknown>): Promise<T>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need any generic (T) here

Copy link
Member

@lahmatiy lahmatiy Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function should return Promise<any>. It would be nice to add typings on generator w/o any/unknown if possible

Copy link
Member

@smelukov smelukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some notes above

@lexich
Copy link
Contributor Author

lexich commented Sep 13, 2021

@lahmatiy @smelukov Some updates

index.d.ts Outdated
declare module '@discoveryjs/json-ext' {
import { Readable } from 'stream';

type TReplacer = (this: any, key: string, value: any) => AnalyserNode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why AnalyserNode was used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missprint(((

index.d.ts Outdated
declare module '@discoveryjs/json-ext' {
import { Readable } from 'stream';

type TReplacer = (this: any, key: string, value: any) => any;
Copy link
Member

@lahmatiy lahmatiy Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replacer could be an array of number | string or null. Standard library has an overload for this case.
image

index.d.ts Outdated

type TReplacer = (this: any, key: string, value: any) => any;

export function parseChunked(stream: Readable | (() => AsyncGenerator<any, any, any>)): Promise<any>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be something like:

export function parseChunked(input: Generator<string, never, void> | AsyncGenerator<string, never, void> | (() => (Iterable<string> | AsyncIterable<string>))): Promise<any>;

@lahmatiy
Copy link
Member

LGTM
@lexich Thank you!

@lahmatiy lahmatiy merged commit 4ffddc1 into discoveryjs:master Sep 13, 2021
@lexich
Copy link
Contributor Author

lexich commented Sep 14, 2021

@lahmatiy Cool, can you bump npm version?

@lahmatiy
Copy link
Member

@lexich Done. Published as 0.5.4
I tweaked a bit typings after my experiments. Your initial suggestion with just a function with Iterator/AsyncIterator for parseChunked() was enough, so I removed Generators

@lahmatiy
Copy link
Member

@lexich My bad, 0.5.4 didn't contain index.d.ts file. Just published 0.5.5 with a fix

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 this pull request may close these issues.

None yet

3 participants