MithrilJS / mithril.d.ts

Types for mithril.js
MIT License
80 stars 11 forks source link

Property 'redraw' does not exist on type 'Event' #17

Open pygy opened 7 years ago

pygy commented 7 years ago

Hey there :-)

It may be nice to have maybe a Mithril.Event with an added redraw: boolean field.

Or did I miss it?

spacejack commented 7 years ago

Yeah that would be handy as a convenience type to include. I think you'd still need to annotate it yourself:

m('button', {onclick: (e: m.Event) => {e.redraw = false}}, "Don't redraw!");

Unless we can do something clever with the Attrs type...

spacejack commented 7 years ago

Thinking about this a bit more, might be more useful to extend all possible events. It could be made more user friendly by adding these and these (and other...?) properties to Attrs.

Eg:

export interface VEvent {
    redraw: boolean
}

export interface Attrs {
    // ...
    onblur?: (this: HTMLElement, ev: FocusEvent & VEvent) => any;
    onclick?: (this: HTMLElement, ev: MouseEvent & VEvent) => any;
    // etc...
spacejack commented 7 years ago

Here's a gist of everything I can think of at the moment:

https://gist.github.com/spacejack/73ae839c4a80a2dfaa88294caec3605f

spacejack commented 7 years ago

I've added a new branch event-types.

@isiahmeadows, @andraaspar what do you think: https://github.com/spacejack/mithril.d.ts/compare/event-types

pygy commented 7 years ago

LGTM :-)

dead-claudia commented 7 years ago

LGTM, although I wish we could concatentate string keys with mapped types, so we wouldn't need to manage the big list ourselves... (TypeScript doesn't allow it though, sadly.)

spacejack commented 7 years ago

Something I should point out about this change, if you're using external event handler functions, you'd need to annotate them like this: https://github.com/spacejack/mithril.d.ts/blob/event-types/test/test-api.ts#L649

oldrich-s commented 7 years ago

@isiahmeadows Is it not solved by my proposal?: https://github.com/spacejack/mithril.d.ts/issues/24