Skip to content

Untyped function calls #236

Closed
Closed
@RyanCavanaugh

Description

@RyanCavanaugh

Comments from @vladima

In certain cases old compiler used to emit "Value of type is not callable. Did you mean to include 'new'" error when during analysis of call expression discover that type does not have call signatures and function being called was bound to constructor' symbol. This yields quite inconsistent results, for example this code will contain error:

class A { }
var x = A();

but this one - does not:

class A { }
var x = A(); // error
interface I { new (): I };
var c: I;
var y = c(); // OK
var c1: { new (): string };
var y1 = c1(); // OK

Per spec (4.12 Function calls) all these examples are correct and will result in untyped call. However I think having error here still has value because in most cases it will correctly signal about missing 'new'.


@ahejlsberg :

I think an untyped call should be permitted only if the type has no signatures at all (call or construct). Technically that's a breaking change, but I think it is a good one. The current behavior makes little sense and I highly doubt the change would break any real world code.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueSpecIssues related to the TypeScript language specification

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions