@types/react-virtualized typings are producing TS errors

时间:2017-08-30 20:47:40

标签: reactjs typescript react-virtualized

I'm using:

  • LSApplicationQueriesSchemes (though I can reproduce this error with 2.4.0 as well)
  • Info.plist
  • import requests url ="http://someapi/v1/auth" payload = {'username': '', 'password': ''} s1 = requests.post(url, headers={"content-type":"application/json"}, data=json.dumps(payload)) print s1.status_code
  • typescript 2.1.6

TS is complaining about the following (example) code:

react 15.6.1

Specifically, it gives me this error:

react-virtualized 9.9.0

Notably, if I go in and edit @types/react-virtualized 9.7.3 directly I can fix it by changing:

import * as React from "react";
import { List, ListRowProps } from "react-virtualized";

class TestComponent extends React.PureComponent<{}, {}> {
    public render() {
        return (
            <List
                width={300}
                height={300}
                rowCount={100000}
                rowHeight={30}
                rowRenderer={this.rowRenderer}
            />
        );
    }

    private rowRenderer(props: ListRowProps) {
        return <div
                 key={props.key}
                 style={props.style}
               />;
    }
}

to

error TS2605: JSX element type 'List' is not a constructor function for JSX elements.

which makes sense to me given that the definition of List.d.ts is

export class List extends PureComponent<ListProps> {

i.e. export class List extends PureComponent<ListProps, {}> { requires two type parameters, so a class cannot extend PureComponent but it can extend class PureComponent<P, S> extends Component<P, S> { } .

Are my assumptions correct? Is there a bug in PureComponent caused by an attempt to extend PureComponent<T>? Or am I using incompatible versions of these packages? Or is there a TypeScript setting that I need to be using to allow this?

1 个答案:

答案 0 :(得分:1)

想出来了!

我使用的是UITableViewController的过时版本。把它推到最新版本修复了我的问题。