Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jstasiak opened this issue Jul 25, 2023 · 6 comments · Fixed by #55165
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@jstasiak
Copy link

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.

@MartinJohns
Copy link
Contributor

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.

Most likely you're having a tsconfig.json with noImplicitAny enabled. When running tsc on individual files the compiler won't use your project configuration, and the default value for noImplicitAny is false.

@jstasiak
Copy link
Author

Oh yes, noImplicitAny is very much enabled (in the local project and in the playground).

@Andarist
Copy link
Contributor

Bisected this to this diff. It should be safe to say that this has been changed by #53607

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 25, 2023
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.3.0 milestone Jul 25, 2023
@ahejlsberg
Copy link
Member

I'll take a look.

@Andarist
Copy link
Contributor

For what it's worth, this circularity was introduced by this call that tries to choose between undefined and void based on the contextual return type. That leads to requesting the other signature's return type and it requests the first one again (here) because it is in its compositeSignatures.

@jstasiak
Copy link
Author

Thank you all, I can confirm the problem is gone in the current nightly (5.2.0-dev.20230728).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants