-
Notifications
You must be signed in to change notification settings - Fork 211
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
Is there Typescript support? #145
Comments
If you can suggest an appropriate fix to |
I'm looking into it, defining typed definition is actually pretty simple unless you use default exports and babel (see here #5565) as it is the case on this repository. I'm going through the discussion and trying to understand what would be the best approach to fix it. If I success on understanding all of that magic I'll submit a PR |
I am curious about the update here? I am not getting the above error or exception here is my import |
I haven't had much time to do more proper research in order to create my formal PR however this is how I'm using it right now. I'm only using import { Icons, Language } from "react-checkbox-tree";
const CheckboxTree = require("react-checkbox-tree");
export { Icons, Language };
/** Redeclare type definitions from react-checkbox-tree because they are
* currently wrong, if its fixed we could just use and re-export them
* see: https://github.com/jakezatecky/react-checkbox-tree/issues/145
* https://github.com/jakezatecky/react-checkbox-tree/issues/127
* https://github.com/jakezatecky/react-checkbox-tree/pull/48
*/
export interface Node {
label: React.ReactNode; // On the typed definitions this JSX.Element
value: string | number;
children?: Array<Node>;
className?: string;
disabled?: boolean;
icon?: JSX.Element;
showCheckbox?: boolean;
title?: string;
}
export interface CheckboxProps {
nodes: Array<Node>;
checked: Array<string | number>;
expanded: Array<string | number>;
onCheck: (checked: Array<string>) => void;
onExpand: (expanded: Array<string>) => void;
disabled?: boolean;
expandDisabled?: boolean;
expandOnClick?: boolean;
icons?: Icons;
lang?: Language;
name?: string;
nameAsArray?: boolean;
nativeCheckboxes?: boolean;
noCascade?: boolean;
onlyLeafCheckboxes?: boolean;
optimisticToggle?: boolean;
showExpandAll?: boolean;
showNodeIcon?: boolean;
showNodeTitles?: boolean;
onClick?: (event: { checked: boolean; value: string | number }) => void;
} |
@djyako the As far as the issue @Luis-Palacios has, I am not quite sure what is different between If I am happy to provide TypeScript support given that the |
I just started using this, and I changed the interface to React.ReactNode, and it seems to work. But I haven't really gotten to use it properly yet and the graphics look really weird (probably just because I have to connect the css), I'll look into it further next week. But yeah, setting it to ReactNode seems to let you set strings to label and it displays the string in the tree view. |
Followup: This leads to issues when you have a build server since it will just npm install the packages which will still contain the un-updated interface. However, you can use the original interface if you explicitly send in an element to the label parameter. I suggest updating the example code to explicitly use an element input as this won't cause all typescript users to crash. I.e.
|
Merged #169. |
I noticed that a type definition exist and I have read through some conversations on issues and PR that suggest some attempts have been done in order to support typescript however I'm currently trying to use it and I'm running into multiple errors.
I would like to know if currently, this package type definition is correct because it does not seem to be
I run into this error if I try the basic example on
`"Type '{ value: string; label: string; children: { value: string; label: string; }[]; }[]' is not assignable to type 'Node[]'.
Type '{ value: string; label: string; children: { value: string; label: string; }[]; }' is not assignable to type 'Node'.
Types of property 'label' are incompatible.
If I change the way I import the package to
const CheckboxTree = require('react-checkbox-tree');
then it works but without any type supportThe text was updated successfully, but these errors were encountered: