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
1 task done
raptoria opened this issue Jul 23, 2018 · 1 comment
Closed
1 task done

Typescript error using Tree component #11423

raptoria opened this issue Jul 23, 2018 · 1 comment
Assignees
Labels
🤔 Need Reproduce We cannot reproduce your problem

Comments

@raptoria
Copy link

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 });
    }
    
}

@zombieJ zombieJ added 🤔 Need Reproduce We cannot reproduce your problem help wanted The suggestion or request has been accepted, we need you to help us by sending a pull request. labels Aug 23, 2018
@ant-design-bot
Copy link
Contributor

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.

@zombieJ zombieJ removed the help wanted The suggestion or request has been accepted, we need you to help us by sending a pull request. label Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Need Reproduce We cannot reproduce your problem
Projects
None yet
Development

No branches or pull requests

3 participants