Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
How can I do generic function with return TypedEmitter<T>

I want to make a tiny system that hold emitter for specific interface like this.

I am using https://github.com/binier/tiny-typed-emitter

Please help me what I am do wrong. Thanks you alot.

interface IEvenListener
{
}

interface IPlayerJoinedListener extends IEvenListener
{
    onPlayerJoined: (playerId: string) => void;
}

let emitter: TypedEmitter = ...;

function getEmitter<T extends IEvenListener>(): TypedEmitter<T> // error here
{
    return emitter as TypedEmitter<T>;
}

const messageEmitter = getEmitter<IPlayerJoinedListener>();

But it print out error

Type 'T' does not satisfy the constraint 'ListenerSignature<T>'.
Type 'IEvenListener' is not assignable to type 'ListenerSignature<T>'.ts(2344)
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

It should be

getEmitter<T extends ListenerSignature<T>>
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!