Skip to content

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

Closed
@JsonFreeman

Description

@JsonFreeman
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'!

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDuplicateAn existing issue was already createdHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions