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

Ability to extend static Event interface #22978

Closed
Busyrev opened this issue Mar 29, 2018 · 4 comments
Closed

Ability to extend static Event interface #22978

Busyrev opened this issue Mar 29, 2018 · 4 comments

Comments

@Busyrev
Copy link
Contributor

Busyrev commented Mar 29, 2018

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.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 29, 2018

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..

@mhegazy
Copy link
Contributor

mhegazy commented Mar 29, 2018

Is it required to be on the global Event? can you declare a wrapper?

@Busyrev
Copy link
Contributor Author

Busyrev commented Mar 29, 2018

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.

@Busyrev
Copy link
Contributor Author

Busyrev commented Apr 4, 2018

Decided to fork d.ts files to project and edit them, exlude from lib section in tsconfig.

@Busyrev Busyrev closed this as completed Apr 4, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants