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

Infer type arguments from 'super()' calls #27584

Open
DanielRosenwasser opened this issue Oct 5, 2018 · 0 comments
Open

Infer type arguments from 'super()' calls #27584

DanielRosenwasser opened this issue Oct 5, 2018 · 0 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Oct 5, 2018

interface Component {
  whatever: number;
}

type ComponentConstructor = new <T = {}>(extra: T) => Component & T;
declare const Component: ComponentConstructor;

class ReallyOldComponent extends Component {
  constructor() {
    super({ name: "Methuselah", age: 969 });
  }
  blah() {
    this.whatever;
    this.age;
  }
}

Ideally this would produce no errors; in fact, ideally I wouldn't need to specify any type parameter defaults on ComponentConstructor's signature. However, instead, T is inferred as {} and in blah it is an error to access this.age.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant