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

Support 'static' to be used with 'abstract' and generic type #10603

Closed
k8w opened this issue Aug 30, 2016 · 3 comments
Closed

Support 'static' to be used with 'abstract' and generic type #10603

k8w opened this issue Aug 30, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@k8w
Copy link

k8w commented Aug 30, 2016

TypeScript Version: 2.0.0

Code

abstract Class BaseClass<T>{
    abstract static defaultValue:T;
    // ...
}

interface Format{
    //...
}

class ClassA extends BaseClass<Format>{
    static defaultValue:Format = { ... }
}

Expected behavior:
Can define static member in abstract class, so that force child classes contains it.
Such as defaultProps in React.Component

Actual behavior:
Neither interface nor abstract class can achieve this.

@k8w k8w changed the title Support 'static' to be used with 'abstract' Support 'static' to be used with 'abstract' and generic type Aug 30, 2016
@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Aug 30, 2016
@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jun 5, 2017

This is more general than the generic type use case:

  abstract class Base {
    abstract foo: string
    static bar: string
  }
  class BaseExtended extends Base {
    foo = '1'
    // expected error because static property is missing, but got none
    // static bar = '1'
  }

For context, I want this feature so I can properly type the static properties on my React class components. The React typings on DefinitelyTyped define a Component class, and a ComponentClass interface which includes the constructor and the static properties such as propTypes, displayName, and defaultProps. To type check a class component including its static properties, one has to define a class that extends Component and annotate it as ComponentClass:

  // error as expected, displayName should be string
  const ReactComponent: ComponentClass<any> = class extends Component<any, any> {
    static displayName = 1
    render() {
      return <div>{this.props.name}</div>
    }
  };

If we had the feature requested here, we could consolidate the ComponentClass interface and the Component class into an abstract class with static properties.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 28, 2017

looks like a duplicate of #14600

@mhegazy mhegazy added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Aug 28, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 12, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Sep 12, 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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants