TS2577
Return type annotation circularly references itself.
Broken Code ❌
type OurReply = ReturnType<typeof reply>;
function reply(text: string): OurReply {
if (text === 'Hello') {
return 'Hi!';
}
if (text === 'Goodbye') {
return 'Bye!';
}
return "What's up?";
}Fixed Code ✔️
You can remove the circular reference by removing the explicit return type (OurReply) from the signature of your function:
type OurReply = ReturnType<typeof reply>;
function reply(text: string) {
if (text === 'Hello') {
return 'Hi!';
}
if (text === 'Goodbye') {
return 'Bye!';
}
return "What's up?";
}