Skip to content

Error on function type that comes from a function declaration that is declared after usage site #1738

@dragomirtitian

Description

@dragomirtitian

Steps to reproduce

let arr: any[] = [];

// Move fnDeclaration here and it works 
declare let mapFn: typeof fnDeclaration | ((v: any) => number);
// declare let mapFn: ((s: string) => string) | ((v: any) => number); // Also works ok

arr.map(mapFn instanceof Function ? mapFn : i => i); // Error in TS GO


function fnDeclaration(s: string): string {
    return s;
}

Playground Link

Behavior with typescript@5.8

Type checks without errors.

Behavior with tsgo

If fnDeclaration appears after the usage in typeof fnDeclaration we get an error on the arr.map call.

Metadata

Metadata

Assignees

Labels

Domain: Type CheckingRelated to type checking, grammar checkingType OrderingAn issue related to ordering of types

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions