Closed
Description
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
- This is a crash
- This is the behavior in every version I tried
- I was unable to test this on prior versions because it depends on the brand new template literal types introduced in 4.1
⏯ Playground Link
Playground link with relevant code
💻 Code
import { EventEmitter } from 'events';
interface Test<T> {
on(event: 'error', listener: (error: any) => any): this;
on(event: `__${string}`, listener: (data: string, isError: true) => any | ((data: T, isError: false) => any)): this;
once(event: 'error', listener: (error: any) => any): this;
once(event: `__${string}`, listener: (data: string, isError: true) => any | ((data: T, isError: false) => any)): this;
emit(event: 'error', error: any): boolean;
emit(event: `__${string}`, data: string, isError: true): boolean;
emit(event: `__${string}`, data: T, isError: false): boolean;
}
class Test<T> extends EventEmitter {
public test() {
// In my case - I was using a package that could provide null, or any type of data, so they used `any` - but I was expecting a string.
const data: any = 'test';
const key = `__${data as string}` as const;
// In my case, I had 2 values that were nullable - the error, or the data. One of them is guranteed to be present, so "(a ?? b)!" is the way to go.
const nullableProp1: T | null = 'test' as any;
const nullableProp2: string | null = 'test' as any;
// If you start writing out this line, it will compile with regular type errors until the 2nd parameter, at which point everything breaks.
if (key) this.emit(key, (nullableProp1 ?? nullableProp2)!, true as boolean);
}
}
🙁 Actual behavior
The Typescript compiler fails to pick an overload, and seems to recurse down past the maximum stack call size. This is reflected in the browser console when on the playground, and of course, locally
🙂 Expected behavior
The Typescript compiler successfully picks an overload and continues on.
Metadata
Metadata
Assignees
Labels
No labels