← 输入框|github.com|刷新
Skip to content

Untyped function calls #236

Closed
Closed

Description

Comments from Vladimir Matveev (@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'.


Anders Hejlsberg (@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.

Activity

  1. RyanCavanaugh commented on Jul 24, 2014

    @RyanCavanaugh
    MemberAuthor

    Tried out on real world code and found no issues, unsurprisingly. Discussion in design meeting was uncontroversial. Move forward with implementation and spec change.

  2. sophiajt commented on Jul 24, 2014

    @sophiajt
    Contributor

    Please assign to Anders for spec change when complete. Thanks!

  3. added a commit that references this issue on Jul 25, 2014
  4. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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