Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions src/__tests__/__snapshots__/main-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1465,3 +1465,115 @@ Object {
},
}
`;

exports[`main fixtures processes component "component_29.js" without errors 1`] = `
Object {
"description": "",
"displayName": "MyComponent",
"methods": Array [],
"props": Object {
"prop": Object {
"description": "",
"flowType": Object {
"name": "T",
},
"required": true,
},
},
}
`;

exports[`main fixtures processes component "component_30.js" without errors 1`] = `
Object {
"description": "",
"displayName": "MyComponent",
"methods": Array [],
"props": Object {
"prop": Object {
"description": "",
"flowType": Object {
"name": "string",
},
"required": true,
},
},
}
`;

exports[`main fixtures processes component "component_31.js" without errors 1`] = `
Object {
"description": "",
"displayName": "MyComponent",
"methods": Array [],
"props": Object {
"prop": Object {
"description": "",
"flowType": Object {
"name": "T",
},
"required": true,
},
},
}
`;

exports[`main fixtures processes component "component_32.js" without errors 1`] = `
Object {
"description": "",
"displayName": "Segments",
"methods": Array [
Object {
"docblock": null,
"modifiers": Array [],
"name": "foo",
"params": Array [
Object {
"name": "props",
"optional": undefined,
"type": Object {
"alias": "Props",
"name": "signature",
"raw": "{
segments: Array<T>,
}",
"signature": Object {
"properties": Array [
Object {
"key": "segments",
"value": Object {
"elements": Array [
Object {
"name": "T",
},
],
"name": "Array",
"raw": "Array<T>",
"required": true,
},
},
],
},
"type": "object",
},
},
],
"returns": null,
},
],
"props": Object {
"segments": Object {
"description": "",
"flowType": Object {
"elements": Array [
Object {
"name": "T",
},
],
"name": "Array",
"raw": "Array<T>",
},
"required": true,
},
},
}
`;
11 changes: 11 additions & 0 deletions src/__tests__/fixtures/component_29.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

type Identity<T> = T;

type Props<T> = {
prop: Identity<T>,
}

export default function MyComponent<T>(props: Props<T>) {
return <div>Hello World</div>
}
11 changes: 11 additions & 0 deletions src/__tests__/fixtures/component_30.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

type Identity<T> = T;

type Props = {
prop: Identity<string>,
}

export default function MyComponent(props: Props) {
return <div>Hello World</div>
}
11 changes: 11 additions & 0 deletions src/__tests__/fixtures/component_31.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

type Identity<T> = T;

type Props<T> = {
prop: Identity<Identity<T>>,
}

export default function MyComponent<T>(props: Props<T>) {
return <div>Hello World</div>
}
13 changes: 13 additions & 0 deletions src/__tests__/fixtures/component_32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from "react";

type Props<T> = {
segments: Array<T>,
};

export default class Segments<T> extends React.Component<Props<T>> {
render(): React.Node {
return null;
}

foo(props: Props<T>) {}
}
8 changes: 8 additions & 0 deletions src/utils/getFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ function handleGenericTypeAnnotation(
);
}

if (
typeParams &&
typeParams[type.name] &&
typeParams[type.name].value.type === t.GenericTypeAnnotation.name
) {
return type;
}

if (typeParams && typeParams[type.name]) {
type = getFlowTypeWithResolvedTypes(resolvedPath, typeParams);
}
Expand Down