-
Notifications
You must be signed in to change notification settings - Fork 210
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 Support #71
Comments
Hi declare module 'react-sortablejs' {
import Sortable from 'sortablejs';
export interface SortableProps<ItemData, ListProps> {
options?: Sortable.Options;
onChange?: (list: ItemData[], sortable: Sortable, event: Sortable.SortableEvent) => void;
tag?: string | React.ComponentType<ListProps>;
style?: React.CSSProperties;
}
export default class SortableComponent<ItemData, ListProps> extends React.Component<
SortableProps<ItemData, ListProps>
> {}
} I also installed
I'm importing the Sortable component like this: import Sortable from 'react-sortablejs'; Tell me if it works for you. We could submit this to |
Hi Godefroy, That looks great! I will try it within 24 hours. I'm a bit confused on how I actually converted the whole package into a Typescript file to the best of my ability. What are your thoughts on it? You can import it into your project using package name https://github.com/waynevanson/tsc-react-sortablejs
We should definitely submit this to I also feel we should clean up this component, as it's hard to read and manage. I feel like making a |
From https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package
|
We have 3 solutions:
You picked solution 2 but you still have a lot of I guess we could remove the generic @cheton What do you think? |
Sorry, I closed by accident. For a short term solution, I modified your declaration file given below. This is because it was giving me a JSX Constructor Error declare module 'react-sortablejs' {
import React from 'react';
import Sortable from 'sortablejs';
class ReactSortable extends React.Component<Props> {
public options: Sortable.Options;
}
export interface Props extends React.ClassAttributes<Component> {
onChange?: (list: ItemData[], sortable: Sortable, event: Sortable.SortableEvent) => void;
options?: Sortable.Options;
tag?: string | React.ComponentType<ListProps>;
style?: React.CSSProperties;
className?: string;
}
export = ReactSortable;
}
There are some types that I do not understand yet. The goal is to have no
I made it as a proof of concept. Ideally with suggestion 2, this repo transforms into a Typescript project.
With some modifications it works, but considering how small this project is (just a component), a rewrite wouldn't be too difficult and it's an all-in-one solution for the project. The benefits of a Typescript rewrite outweigh the cons. I'd love to hear what @cheton has to say. |
@owen-m1 it looks like @cheton is not maintaining this package, many issues are open etc. Even the build fails, according to the indicator. I'd be happy to maintain this, or perhaps in the meantime you'd be able to help us push Typescript into this repository. What do you think about this? Currently, I find the code on this package hard to work with. In comparison, the Vue.Draggable package is remarkable and works right out of box without configuration. In react-sortablejs, there are features such as sorting an input list to state and better nesting support which should be part of this package. Have a look at https://github.com/waynevanson/tsc-react-sortablejs to see a basic conversion. It's the same as the current package and handles strict null checks. there are some any's as it was probably written without 100% type safety in mind. Aside from my current efforts, I'd much prefer this being either a FunctionComponent or break down the Class component into testable parts. Which route do you think is a good idea? |
@waynevanson I don't know if he is still maintaining this or not. You'll have to email him about this, this is his project. If he approves, I can add you to the project. I can help in any way as the "Sortable expert" but I don't know React :). |
Thanks, @owen-m1 . I've sent him an email asking if I'd be able to switch maintainers, or if he doesn't want to switch, if he can reply to this thread. |
@waynevanson Would this package need Typescript support if Sortable uses Typescript? Or do you mean writing this package itself in Typescript? |
Hi @waynevanson I'm currently busy at work in the last few months and the situation will not end until August, so I don't have much time to watch and respond GitHub issues. Also, I'm not an expert in TypeScript, I'd be happy if someone can help maintain / contribute to this project to complete TypeScript support, I can help do code review and publish new releases to NPM. @owen-m1 Can you help add @waynevanson as a maintainer for this repo. Thank you. |
Sure, @waynevanson I sent you an invite. |
There we are boys: #83 |
Hi All,
I know there is an
@types/sortablejs
file out in the wild, but in the react world I don't know how to hook it up correctly, due to unfimilarity with the react specific implementation of SortableJs. I've used VueJs Component which works easily and am familiar with many SortableJS options.From the example in this
README.md
, I entered this code:The squiggly lines of death are under
'react-sortablejs'
, which displays the following message on hover:I am trying to go through the typescript documentation for an answer, but can't figure out how to extend the
sortablejs
types intoreact-sortablejs
Any ideas?
On resolution of this, we should link
@types/sortablejs
as a dependency in future builds alongside a declaration form for this package. I'll be happy to try doing this once I start using this Component.The text was updated successfully, but these errors were encountered: