EVT
GitHubHomePlaygroud
v2
v2
  • 🚀EVT Overview
  • 📖API Documentation
    • Evt<T>
      • Async iterator
      • evt.attach*(...)
      • evt.post*(data)
      • evt.waitFor(...)
      • evt.evt[Attach|Detach]
      • evt.pipe(...)
      • evt.getHandlers()
      • evt.isHandled(data)
      • evt.detach(ctx?)
      • evt.enableTrace(...)
      • evt.setMaxHandlers(n)
      • toStateful(initialState)
      • evt.getStatelessOp(op)
      • Evt.create(initalState?)
      • Evt.newCtx<T>()
      • Evt.getCtx(object)
      • Evt.from<T>(...)
      • Evt.merge([ evt1, evt2, ... ])
      • Evt.loosenType(evt)
      • Evt.factorize(evt)
      • Evt.asPostable(evt)
      • Evt.asNonPostable(evt)
      • Evt.setDefaultMaxHandlers(n)
    • Ctx<T>
    • Operator<T, U> (type)
    • StatefulEvt<T>
    • Helper types
    • Handler<T, U> (type)
  • 🪝React hooks
  • 🔩From EventEmitter to Evt
  • ⬆️v1 -> v2
Powered by GitBook
On this page
Edit on GitHub
  1. API Documentation
  2. Evt<T>

Evt.loosenType(evt)

This is the identity function with special type annotations.

Swipe the type argument with a superset without giving up type safety.

If A is assignable to B ⇒ Evt<A> is assignable to Evt<B>

e.g:Evt<1|2|3> is assignable to Evt<number> however typescript wont let you do this assignation. This is where Evt.loosenType come in handy.

import { Evt } from "evt";

declare const evFooBar: Evt<"FOO" | "BAR">; 
declare function myFunc(evtText: Evt<string>): void;

myFunc(evtFooBar); //Gives a type error; 
myFunc(Evt.loosenType(evtFooBar)); //OK
PreviousEvt.merge([ evt1, evt2, ... ])NextEvt.factorize(evt)

Last updated 2 years ago

📖