Skip to content

Recursive function type is printed using "any" if the function is not in scope #475

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

Closed
JsonFreeman opened this issue Aug 18, 2014 · 2 comments
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created Help Wanted You can do this

Comments

@JsonFreeman
Copy link
Contributor

var x = function f() { return f; };
var x = function () { var y; return y; };

We get the following error message:
Subsequent variable declarations must have the same type. Variable 'x' must be of type '() => any', but here has type '() => any'.

This is essentially the same as #463. The first declaration of x has type () => typeof f, but because f is not in the global scope, we say it is any, even though it is clearly not.

We have a similar problem for function declarations (and likely for module instances and class constructors):

function g() {
    return function f() {
        return f;
    };
}

var numberFn = <() => number>(g());

We get the following error on the type assertion:
Neither type '() => number' nor type '() => any' is assignable to the other.

But in fact '() => number' is assignable to '() => any'!

@JsonFreeman
Copy link
Contributor Author

The relevant test case for this bug is:
tests/cases/compiler/functionExpressionReturningItself.ts

@jmatthiesen jmatthiesen added this to the TypeScript 1.2 milestone Aug 18, 2014
@sophiajt sophiajt modified the milestones: Community, TypeScript 1.3 Sep 8, 2014
@mhegazy mhegazy added the Help Wanted You can do this label Feb 20, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Feb 20, 2016

closing in favor of #463

@mhegazy mhegazy closed this as completed Feb 20, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 20, 2016
@mhegazy mhegazy removed this from the Community milestone Apr 26, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

5 participants