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

initialized property that references this triggers "referenced directly or indirectly in its own initializer." when referenced outside the constructor #16892

Closed
nevir opened this issue Jul 2, 2017 · 2 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@nevir
Copy link

nevir commented Jul 2, 2017

This seems like a bug; but let me know if this would be better suited for SO

TypeScript Version: 2.4.1 (and prior)

Code

import * as React from 'react';
import * as dapper from '@convoy/dapper';

const STYLES = dapper.compile({
  root: { padding: 10 },
});

export class App extends React.Component {
  styles = dapper.reactTo(this, STYLES);

  render() {
    return <div className={this.styles.root}>;
  }
}

Expected behavior:

Compiles without complaint

Actual behavior:

When render() references this.styles.root, both styles and render are flagged with:

'[property]' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

If I remove the reference to this.styles.root, neither property has an error. Also, the type of styles appears correctly inferred as { root: string }

@nevir nevir changed the title initialized property that references this triggers "referenced directly or indirectly in its own initializer." when outside the constructor initialized property that references this triggers "referenced directly or indirectly in its own initializer." when referenced outside the constructor Jul 2, 2017
@mhegazy mhegazy added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Aug 24, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 24, 2017

The type of the property depends on the type of the class, which includes the type of the property. the compiler breaks these circular dependencies by giving declarations the type any. the error message tells you that this occurred. adding an explicit type annotation to styles declaration should avoid the issue.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 8, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

2 participants