Skip to content

TSX variable element #8549

Closed
Closed
@RylanH

Description

@RylanH

TypeScript Version:

1.8.10

Code

export class Text extends React.Component<TextProps, {}> {
  _tagName: string = 'div';

  render() {
    return (
      <this._tagName />
    );
  }
}

export class Heading1 extends Text {
 _tagName:string = 'h1';
}

Expected behavior:
No error

Actual behavior:
Throws compilation error 'Cannot find name this'

Workaround

export class Text extends React.Component<TextProps, {}> {
  _tagName: string = 'div';

  render() {
    const self = this;
    return (
      <self._tagName />
    );
  }
}

export class Heading1 extends Text {
 _tagName:string = 'h1';
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions