Joylei / riot-typed

a tiny wrapper layer for riotjs to write riot tags with benefits of typescipt
MIT License
8 stars 1 forks source link

Event.preventUpdate (suggestion) #1

Open danielweck opened 6 years ago

danielweck commented 6 years ago

Hello, thank you for this project :)

I am using the riot-typed package that is currently published on the NPM repository ( https://www.npmjs.com/package/riot-typed ), but instead of using Typings I simply reference your main Riot type definitions from my top-level declarations.d.ts:

/// <reference path="../node_modules/riot-typed/src/riot.d.ts" />

I added this simple extension so that the preventUpdate property (which RiotJS attaches to DOM events) is typed properly:

declare interface RiotEvent extends Event {
    preventUpdate: boolean;
}

Say I have the following Riot Tag specification:

<riot-mytag>
  <button onclick="{ onclickButton }">butt</button>
</riot-mytag>

...I can then use the RiotEvent in place of MouseEvent (or more generally, lib.dom.Event):

    // 'this' type is RiotTag
    this.onclickButton = (ev: RiotEvent) => {
        console.log("CLICK button");

        ev.preventUpdate = true;
    };
danielweck commented 6 years ago

For your information, I forked your project in order to correct a few issues with the TypeScript compiler (implicit function return types). I also added the aforementioned event.preventUpdate property. See: https://github.com/Joylei/riot-typed/compare/master...danielweck:master

Joylei commented 6 years ago

@danielweck

thanks, I'll take a look.