Skip to content

Spurious TS7024 (Function implicitly has return type 'any'...) and TS2577 (Return type annotation circularly references itself) in TS 5.1.x #55145

Closed
@jstasiak

Description

@jstasiak

Bug Report

🔎 Search Terms

  • TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions
  • TS2577: Return type annotation circularly references itself
  • 5.1.6 regression

🕗 Version & Regression Information

  • I see the issue with TS 5.1.3-5.1.6 and the latest nightly.
  • I do not see the issue with TS 5.0.4.
  • This changed between versions 5.0.4 and 5.1.3

⏯ Playground Link

Variant 1 (no return type annotations, 2x TS7024)

https://www.typescriptlang.org/play?target=99#code/GYVwdgxgLglg9mABMAPAFUQUwB5U2AEwGdEBDMATwG0BdAPgAoA3ALkQCVNSCEAbCgIIAnIaQro6ASkQBvRAF8AUMuAMqixJsTqtuxOAKZgMMJgIAaDXs0NpAXjqyFl3TRdad1xAEZ3124gOslZeWhAIRHC8mAB0vHAA5gwA5AASmLzxyZIhevJ+iG6KNDlAA

Variant 2 (I added one return type annotation, I get TS7024 + TS2577):

https://www.typescriptlang.org/play?target=99#code/GYVwdgxgLglg9mABMAPAFUQUwB5U2AEwGdEBDMATwG0BdAPgAoA3ALkQCVNSCEAbCgIIAnIaQro6ASkQBvRAF8AUMuAMqixJsTqtuxOAKZgMMJgIAaDXs0NJbJnBgFEAXjqyFl3TS9ad1xABGX2tbV3cZKwCtCAQiOF5MADpeOABzBgByAAlMXlTMySi9eRDEH0UaIqA

💻 Code

Variant 1

function f<T extends any[]>(v: ReadonlyArray<T>) { }


f([
    [
        undefined,
        () => { },
    ],
    [
        1,
        () => {
            console.log('Hello')
        },
    ],
])

Variant 2

function f<T extends any[]>(v: ReadonlyArray<T>) { }


f([
    [
        undefined,
        (): void => { },
    ],
    [
        1,
        () => {
            console.log('Hello')
        },
    ],
])

🙁 Actual behavior

The code doesn't compile.

What's strange is from my tests it seems that if I run tsc filewithcode.ts it compiles fine but if I run tsc on the whole project it produces errors.

🙂 Expected behavior

I expected the code to compile.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions