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

Non-function properties incorrectly present in type of classes' prototypes #11558

Closed
timruffles opened this issue Oct 12, 2016 · 2 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@timruffles
Copy link

TypeScript Version: 2.0.0

Code

class A {
    foo = "hi";
}

class B {}

// this is fine
const t: { prototype: { foo: string } } = A;

// this complains "types of property 'prototype' are incompatible"
const u: { prototype: { foo: string } } = B;

Expected behavior:

Only function properties should exist in prototypes of classes. This reflects the runtime behaviour (all properties are assigned in constructor).

Actual behavior:

Non-function properties appear in the types of classes' prototypes.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Oct 12, 2016
@RyanCavanaugh
Copy link
Member

We found that a not-insignificant of people used prototype to create property default values. Since there's not any other way to declare that property and it's a very difficult property to use incorrectly, it was better (and simpler) overall to include instance properties in the prototype.

@timruffles
Copy link
Author

Is this documented?

Quite surprising (even if you know about the ES6 pt prop restriction + transpiler's strategy).

@mhegazy mhegazy closed this as completed Apr 21, 2017
@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
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants