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

disallow abstract property declaration with value in class #33356

Closed
4 of 5 tasks
LongTengDao opened this issue Sep 10, 2019 · 4 comments
Closed
4 of 5 tasks

disallow abstract property declaration with value in class #33356

LongTengDao opened this issue Sep 10, 2019 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@LongTengDao
Copy link
Contributor

LongTengDao commented Sep 10, 2019

Search Terms

Suggestion

abstract class C {
    abstract method () :Type;// valid
    abstract property :Type;// valid
    abstract property :Type = value; // this should be invalid, because it doesn't make sense
}

Use Cases

Examples

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Sep 10, 2019
@RyanCavanaugh
Copy link
Member

Breaking changeness aside, I don't see by what logic we would disallow it. TS should always let you write

this.property = value;

in a method body. Disallowing you from using the sugar to do that in the constructor body would be entirely arbitrary

@LongTengDao
Copy link
Contributor Author

LongTengDao commented Sep 10, 2019

@RyanCavanaugh abstract property assignment will always be overriden by sub class, it should not have value assignment behaviour, just like abstract method should not have body block

@RyanCavanaugh
Copy link
Member

A child class can have a bare property declaration without an initializer, thus falling back to the parent value.

Either way, we're not interested in taking a breaking change here.

@LongTengDao
Copy link
Contributor Author

@RyanCavanaugh I see. There is difference between ECMAScript class proposal and TypeScript. In latest proposal, property declaration is define not set, and bare property declaration is equal to = undefined. Now that it's still a proposal, so the breaking problem may be handled together util the proposal be standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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

2 participants