Skip to content

Maybe support for assign resolution in constructors #28688

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

Closed
5 tasks done
reaperdtme opened this issue Nov 27, 2018 · 2 comments
Closed
5 tasks done

Maybe support for assign resolution in constructors #28688

reaperdtme opened this issue Nov 27, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@reaperdtme
Copy link

Search Terms

assign

Suggestion

my constructors usually follow the pattern:

class It {
  prop1: string
  prop2: string
  constructor(props: It) {
    (_ || Object).assign(this, props);
  }
}

With this though, I get the error

property 'prop1' has no initializer and is definitely not assign in the constructor

Though it is.

Typing out all properties in constructor, constructor params and class vars is sadly redundant.

Typescript apparently has the inner workings for assignment awareness, can this be extended to assigning functions?

Use Cases

Above
I'm sure other people can find some dope use cases for an assign type descriptor.

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.
@weswigham weswigham added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Nov 27, 2018
@DanielRosenwasser
Copy link
Member

Duplicate of #26792

@DanielRosenwasser DanielRosenwasser marked this as a duplicate of #26792 Nov 28, 2018
@DanielRosenwasser DanielRosenwasser added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Nov 28, 2018
@typescript-bot
Copy link
Collaborator

This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants