-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Ability to extend static Event interface #22978
Comments
The answer to the general question is to make them classes (#574). there are some wrinkles here about what that entails though, callable constructors, and un-instantiate-able classes.. |
Is it required to be on the global |
In my case there already redefined Event(and some another browser api classes) in global by outer js code. This event does everything that original event does and some more. I can't simply extend Event, I should replace global Event defenition to more complicated defenition (declaration merging resolves issue as I showed in PR). I don't know any way to declare additional static fields to something that declared as 'declare Class'. Of cource I can rename extended Event to another name, but code quality became awful. Mutch better is just add special defenitions to project and define extended functionality for already available types. |
Decided to fork d.ts files to project and edit them, exlude from lib section in tsconfig. |
This is discussion question about extending builtin d.ts in projects.
In my particular case I would like to extend Event static intreface to add some static fields to Event(for special runtime that extends browser runtime).
I have found no way to do it. But for Array there is a way to use declaration merging because ArrayConstructor is separate named interface.
Here is example on playground
Tried it in #22946
@mhegazy thanks for answers in PR.
Question in general:
Find a way how to make any definition extendable without forking builtin d.ts files and changing them manually.
The text was updated successfully, but these errors were encountered: