mithril.d.ts icon indicating copy to clipboard operation
mithril.d.ts copied to clipboard

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

Open pygy opened this issue 8 years ago • 8 comments

Hey there :-)

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

Or did I miss it?

pygy avatar Apr 04 '17 21:04 pygy

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 avatar Apr 05 '17 00:04 spacejack

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 avatar Apr 11 '17 20:04 spacejack

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

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

spacejack avatar Apr 11 '17 20:04 spacejack

I've added a new branch event-types.

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

spacejack avatar Apr 12 '17 03:04 spacejack

LGTM :-)

pygy avatar Apr 12 '17 10:04 pygy

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

dead-claudia avatar Apr 13 '17 13:04 dead-claudia

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

spacejack avatar Apr 27 '17 02:04 spacejack

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

oldrich-s avatar Jul 14 '17 19:07 oldrich-s