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 TypeScript definition #4

Merged
merged 1 commit into from
Feb 17, 2020

Conversation

ExE-Boss
Copy link
Contributor

@ExE-Boss ExE-Boss commented May 12, 2019

| 'url';

/** Helper type to flatten nested mapped types */
declare type Identity<T> = {} & {[K in keyof T]: T[K]};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This converts something like: Pick<IncomingMessage, Exclude<"complete", keyof T> | Exclude<"destroy", keyof T> | Exclude<"headers", keyof T> | Exclude<"httpVersion", keyof T> | Exclude<"httpVersionMinor", keyof T> | Exclude<"httpVersionMajor", keyof T> | Exclude<"method", keyof T> | Exclude<"rawHeaders", keyof T> | Exclude<"rawTrailers", keyof T> | Exclude<"setTimeout", keyof T> | Exclude<"socket", keyof T> | Exclude<"statusCode", keyof T> | Exclude<"statusMessage", keyof T> | Exclude<"trailers", keyof T> | Exclude<"url", keyof T>> (which is what mimicResponse gets interpreted as) into:

{
    complete: boolean;
    destroy: (error?: Error | undefined) => void;
    headers: http.IncomingHttpHeaders;
    httpVersion: string;
    httpVersionMinor: number;
    httpVersionMajor: number;
    method?: string | undefined;
    ... 7 more ...;
    url?: string | undefined;
}

@@ -33,4 +33,6 @@ module.exports = (fromStream, toStream) => {

toStream[prop] = typeof fromStream[prop] === 'function' ? fromStream[prop].bind(fromStream) : fromStream[prop];
}

return toStream;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes it possible to alter the type of toStream.

@sindresorhus
Copy link
Owner

I appreciate the PR, but I commented to @BendingBender exactly because I prefer him to do it. He knows exactly how to create the type definitions correctly. I don't really have time to review random TS definition submissions.

@sindresorhus sindresorhus changed the title feat: Add TypeScript type definition Add TypeScript definition Feb 17, 2020
@sindresorhus sindresorhus merged commit 910add8 into sindresorhus:master Feb 17, 2020
@sindresorhus
Copy link
Owner

Thanks :)

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

2 participants