React-virtualized: Ship flow typings

Created on 20 Sep 2016  路  15Comments  路  Source: bvaughn/react-virtualized

I see React Virtualized annotated with Flow. It would nice if React Virtualized was distributed with flow typings.

enhancement help wanted

All 15 comments

Hey @andreypopp. This seems like a nice suggestion. 馃憤

Know of any libraries that do this [that I could use as a reference]?

So what I do usually if library already uses flow is just copy original sources along by change their extension to .js.flow (Flow uses them instead of compiled JS to get type info from).

Also you are using propTypes now, it might be beneficial to switch to types for props because types can express much more type info: for example callbacks will describes what arguments they accept.

Flow types for props then can be compiled to propTypes (with the help of corresponding Babel plugin) for consumers who don't use Flow yet.

I can help with that.

So what I do usually if library already uses flow is just copy original sources along by change their extension to .js.flow (Flow uses them instead of compiled JS to get type info from).

Copy to..? (Would it go where the ES6 modules go?)

Also you are using propTypes now, it might be beneficial to switch to types for props because types can express much more type info

Yeah, I've been meaning to make the propTypes => props switch for a while but I just haven't had the time. If you'd like to help- I'd welcome it! 馃槃

So what I do usually if library already uses flow is just copy original sources along by change their extension to .js.flow (Flow uses them instead of compiled JS to get type info from).

Copy to..? (Would it go where the ES6 modules go?)

That's an interesting question... probably in both locations then... this needs a little more investigation.

Agreed 馃憤

So what I do usually if library already uses flow is just copy original sources along by change their extension to .js.flow

Would flow gen-flow-files be preferable?

  gen-flow-files  EXPERIMENTAL: Generate minimal .js.flow files for publishing to npm.

I mean, if it works :)

Would flow gen-flow-files be preferable?

Yes! 馃槃

flow-copy-source is another alternative. It's used in React Motion

Closing this issue for now due to lack of interest. (I don't have the time to tackle it and having open issues that you don't plan on resolving adds stress to a project's maintenance.) If someone would like to pick it up and own it though- that would be fantastic. 馃檱

I know it has been a year, but I'm very interested in this. I was rather surprised that they weren't already available after looking at the source when forking some of the internal renderers. An example I'd love to have work:

// @flow

import React from 'react';
import { SortIndicator } from 'react-virtualized';

import type { HeaderRendererParams } from 'react-virtualized';

type Props = HeaderRendererParams & {
  onLabelClick: () => void,
};

const HeaderRowRenderer = ({
  columnData,
  dataKey,
  disableSort,
  label,
  sortBy,
  sortDirection,
  onLabelClick,
}: Props) => {
  const showSortIndicator = sortBy === dataKey;

  const children = [
    <span
      className="ReactVirtualized__Table__headerTruncatedText"
      key="label"
      title={label}
      onClick={onLabelClick}
    >
      {label}
    </span>,
  ];

  if (showSortIndicator) {
    children.push(
      <SortIndicator key="SortIndicator" sortDirection={sortDirection} />,
    );
  }

  return children;
};

Upon further review, there is references to the flow types being finalized over prop-types in a variety of places (listed below). Even reference to them being part of version 10. Are flow types officially supported? I found some typescript types. The dist files have .js.flow but everything just pulls from prop-types which I assume is work done by the Babel plugin.

External sources: https://github.com/bvaughn/react-virtualized/pull/930/files, https://github.com/bvaughn/react-virtualized/pull/905/files, https://github.com/bvaughn/react-virtualized/pull/950/commits


EDIT: I assume they aren't working as Nuclide didn't pull them in nor does it show typing information like it does with other packages. They also didn't come when I ran $ flow-typed install. I'm curious if this package just exposes them in a non-standard way.

@SavePointSam Flow is currently supported only in dist/es/WindowScroller and dist/es/AutoSizer.

Anything I could do to help?

Not, yet. There's a big rewrite, which may conflict with new changes. Maybe a bit later.

Was this page helpful?
0 / 5 - 0 ratings