Skip to content

Add: typings - #7

Merged
lahmatiy merged 1 commit into
discoveryjs:masterfrom
lexich:feat/typings
Sep 13, 2021
Merged

lahmatiy merged 1 commit into
discoveryjs:masterfrom
lexich:feat/typings

Conversation

@lexich

@lexich lexich commented Sep 13, 2021

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread index.d.ts Outdated

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

@smelukov smelukov Sep 13, 2021 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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

Comment thread 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;

@smelukov smelukov Sep 13, 2021 •

Copy link
Copy Markdown
Member

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 )

@lahmatiy lahmatiy Sep 13, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread index.d.ts Outdated
continueOnCircular?: boolean;
}
): {
minLength: Number;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

number for consistency

Comment thread 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
Copy Markdown
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

@lahmatiy lahmatiy Sep 13, 2021 •

Copy link
Copy Markdown
Member

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

@smelukov smelukov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

some notes above

@lexich

lexich commented Sep 13, 2021

Copy link
Copy Markdown
Contributor Author

@lahmatiy @smelukov Some updates

@lexich
lexich requested review from lahmatiy and smelukov September 13, 2021 08:08
Comment thread index.d.ts Outdated
declare module '@discoveryjs/json-ext' {
import { Readable } from 'stream';

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

missprint(((

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

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

@lahmatiy lahmatiy Sep 13, 2021 •

Copy link
Copy Markdown
Member

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

Comment thread 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
Copy Markdown
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
Copy Markdown
Member

LGTM
@lexich Thank you!

@lahmatiy
lahmatiy merged commit 4ffddc1 into discoveryjs:master Sep 13, 2021
@lexich

lexich commented Sep 14, 2021

Copy link
Copy Markdown
Contributor Author

@lahmatiy Cool, can you bump npm version?

@lahmatiy

Copy link
Copy Markdown
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
Copy Markdown
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.

3 participants