WebReflection / hyperHTML-Element

An extensible class to define hyperHTML based Custom Elements.
ISC License
202 stars 25 forks source link

Add types and typescript example #22

Closed Fredx87 closed 6 years ago

Fredx87 commented 6 years ago

Added definitions for typescript and examples.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 41808e7efb05e4029c69a9b5c0e0c11dafd54e29 on Fredx87:add-typings into 50b70289f98904035fb935c0b81cedf5dbab4e85 on WebReflection:master.

Fredx87 commented 6 years ago

I think the long on* list is pretty awesome but the concept here is that any event, even custom events, starting with on will work just as fine.

These definitions are needed because the HTMLElement interface have these handlers defined as properties: https://github.com/Microsoft/TypeScript/blob/be1c11581e43098bcb6747af50f43b39c762be39/lib/lib.d.ts#L8755 and if you try to write a method that have the same name of a property Typescript will throw an error like this:

TS2425: Class 'HyperHTMLElement<{}>' defines instance member property 'onclick', but extended class 'MyCustomComponent' defines it as instance member function.

Redefining all the handler as methods in the HyperHTMLElement interface fixes this problem.