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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

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.

@zombieJ zombieJ removed the help wanted label Aug 23, 2018

@zombieJ zombieJ closed this in 500ef62 Aug 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment