Evt.asNonPostable(evt)

Evt.asNonPostable() is the identity function with special type annotation

Return the passed evt typed as an object that can't be posted.

Usecase:

Take this example.

You could use this function to enforce that the return type by inferred and save you the trouble of having to import the StatefulReadonlyEvt interface:

import { Evt } from "evt";

//Return an event that post every second.
function generateEvtTick(delay: number) {

    const evtTick= Evt.create(0);

    setInterval(()=> evtTick.state++, delay);

    retrun Evt.asNonPostable(evtTick);

}

const evtTick= generateTick(1000);


evtTick.state++; // TS ERROR
evtTick.post(2); // TS ERROR

Last updated