Skip to content

ResponseConstructor #1518

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

Open
mfulton26 opened this issue Mar 10, 2023 · 3 comments
Open

ResponseConstructor #1518

mfulton26 opened this issue Mar 10, 2023 · 3 comments

Comments

@mfulton26
Copy link

I would like to globally augment the ResponseConstructor (e.g. add the missing json(data, init) static method, safely add my own using unique symbols, etc.).

However I do not see how to do that as var Response isn't defined with a named type.

declare var Response: {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
error(): Response;
redirect(url: string | URL, status?: number): Response;
};

I suggest extracting the type to an interface, e.g. named ResponseConstructor to enable global augmentation of these types.

There are likely other types/constructors that could also be given named types too (e.g. AbortController, etc.).

@saschanaz
Copy link
Contributor

saschanaz commented Mar 15, 2023

The way to extend static part is requested multiple times, I still think the right way to do this is to convert them to class declarations. (Because, well, they are classes.)

@saschanaz
Copy link
Contributor

This specific case will be solved once Gecko or WebKit adds the support in https://bugzilla.mozilla.org/show_bug.cgi?id=1758943 or WebKit/WebKit#10593.

@mfulton26
Copy link
Author

The way to extend static part is requested multiple times, I still think the right way to do this is to convert them to class declarations. (Because, well, they are classes.)

Until microsoft/TypeScript#36813 is supported, declaring them as classes won't work for augmenting Response with properties keyed using unique symbols.

This specific case will be solved once Gecko or WebKit adds the support in https://bugzilla.mozilla.org/show_bug.cgi?id=1758943 or WebKit/WebKit#10593.

That's true but I want to define my own too using unique symbols. e.g. Response[html](), Response[notFound](), etc.

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

No branches or pull requests

2 participants