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

Typescript error using Tree component #11423

Closed
raptoria opened this issue Jul 23, 2018 · 1 comment
Closed

Typescript error using Tree component #11423

raptoria opened this issue Jul 23, 2018 · 1 comment
Assignees

Comments

@raptoria
Copy link

@raptoria raptoria commented Jul 23, 2018

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

3.7.1

Environment

Using Chrome on Windows

Reproduction link

http://seenotesbelow

Steps to reproduce

Import tree component, try to use it..get a typescript error for dataRef attribute on TreeNode

What is expected?

No error message

What is actually happening?

C:/Projects/wakanda/src/components/grid/ToolPanelTreePicker.tsx
(41,59): Property 'dataRef' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<AntTreeNodeProps, ComponentState, any>> ...'.


my code:

import * as React from "react";
import { Tree } from 'antd';
import { AntTreeNodeProps, AntTreeNodeSelectedEvent } from 'antd/es/tree';
const TreeNode = Tree.TreeNode;

export interface IToolPanelProps {
    defaultConfig: any
}

export interface IToolPanelState{
    checkedKeys: Array<string>,
    selectedKeys: Array<string>
}

class ToolPanelTreePicker extends React.Component <IToolPanelProps, IToolPanelState> {
    constructor(props: IToolPanelProps) {
        super(props);

        this.state = {
            checkedKeys:[],
            selectedKeys:[]
        }
    } 
    public render() {
        return (
            <Tree
            checkable={true}
            checkedKeys={this.state.checkedKeys}
            onSelect={this.onSelect}
            selectedKeys={this.state.selectedKeys}
          >
            {this.renderTreeNodes(this.props.defaultConfig.measures)}
          </Tree>
        );
    }

    private renderTreeNodes = (data: any) => {
        return data.map((item:AntTreeNodeProps) => {
          if (item.children) {
            return (
              <TreeNode title={item.title} key={item.key} dataRef={item}>
                {this.renderTreeNodes(item.children)}
              </TreeNode>
            );
          }
          return <TreeNode {...item} key={item.key} />;
        });
      }
    
    private  onSelect = (selectedKeys: Array<string>, info: AntTreeNodeSelectedEvent) => {
        console.log('onSelect', info);
        this.setState({ selectedKeys });
    }
    
}

@ant-design-bot
Copy link
Contributor

@ant-design-bot ant-design-bot commented Aug 23, 2018

Hello @raptoria. Please provide a online reproduction by forking this link https://u.ant.design/codesandbox-repro. Issues labeled by Need Reproduce will be closed if no activities in 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants