Skip to content
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

Method type declarations violate a es6 specification #6138

Closed
falsandtru opened this issue Dec 17, 2015 · 8 comments
Closed

Method type declarations violate a es6 specification #6138

falsandtru opened this issue Dec 17, 2015 · 8 comments
Labels
Breaking Change Would introduce errors in existing code ES6 Relates to the ES6 Spec Suggestion An idea for TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it

Comments

@falsandtru
Copy link
Contributor

var es5obj = {
    method: function(){}
};
var es6obj = {
    method(){}
};

'prototype' in es5obj.method; // true
new es5obj.method(); // ok

'prototype' in es6obj.method; // false
new es6obj.method(); // TypeError: es6obj.method is not a constructor
  1. Methods cannot call with new keyword.
  2. Methods must not have a prototype property.

Class declarations also have same problems.

class C {
    m() {
    }
}
var c: C;
c.m.prototype; // should be a compile error
new c.m(); // should be a compile error

14.3.9 In ECMAScript 2015, the function objects that are created as the values of the [[Get]] or [[Set]] attribute of accessor properties in an ObjectLiteral are not constructor functions and they do not have a prototype own property. In the previous edition, they were constructors and had a prototype property.

http://www.ecma-international.org/ecma-262/6.0/

@DanielRosenwasser
Copy link
Member

It says functions created for get/set accessors, which these functions aren't, so it's not clear that this is actually a problem.

@DanielRosenwasser DanielRosenwasser added the Needs More Info The issue still hasn't been fully clarified label Dec 17, 2015
@falsandtru
Copy link
Contributor Author

I could not find a just said section about this behavior. This spec is a closest explanation about this behavior. I thought this is spec because there is this behavior in chrome and firefox. But edge has not this behavior. Sorry, now I cannot know that which implementation reflects a spec.

@DanielRosenwasser
Copy link
Member

now I cannot know that which implementation reflects a spec.

That's the fun of it though! 😄

@DanielRosenwasser
Copy link
Member

@bterlson any clue what this section corresponds to specifically?

@vladima
Copy link
Contributor

vladima commented Dec 18, 2015

spec is clear and TypeScript should be more strict:
DefineMethod accepts optional parameter functionPrototype that is not passed during PropertyDefinitionEvaluation. Also internally DefineMethod calls FunctionCreate passing in Method as a kind of a function -> for such functions FunctionCreate will pass non-constructor as allocKind to FunctionAllocate and this will not set up [[Construct]] internal method

@falsandtru
Copy link
Contributor Author

I checked v8 and spidermonkey bug tracker but it seems has not reports about this implementation. As a spec, I also agree with @vladima . Edge seems to have correct implementations.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript In Discussion Not yet reached consensus and removed Needs More Info The issue still hasn't been fully clarified labels Dec 18, 2015
@DanielRosenwasser
Copy link
Member

A fix will need a way to propagate this information along with the signature or type. I think this also would be a breaking change.

@DanielRosenwasser DanielRosenwasser added Breaking Change Would introduce errors in existing code ES6 Relates to the ES6 Spec labels Dec 18, 2015
@mhegazy mhegazy added the Suggestion An idea for TypeScript label Jan 7, 2016
@mhegazy mhegazy removed the Bug A bug in TypeScript label Jun 7, 2016
@RyanCavanaugh RyanCavanaugh added Working as Intended The behavior described is the intended behavior; this is not a bug Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it and removed In Discussion Not yet reached consensus Working as Intended The behavior described is the intended behavior; this is not a bug labels Aug 12, 2017
@RyanCavanaugh
Copy link
Member

Doesn't appear to be worth fixing

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Breaking Change Would introduce errors in existing code ES6 Relates to the ES6 Spec Suggestion An idea for TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests

5 participants