Skip to content

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

Closed
@nevir

Description

@nevir

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 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions