Skip to content

Commit

Permalink
[overrides] Fix broken upstream Flow code
Browse files Browse the repository at this point in the history
Addresses part of TS2694
  • Loading branch information
alloy committed Nov 20, 2020
1 parent 75ead21 commit 5e5ee95
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Expand Up @@ -5,7 +5,7 @@ import { ReactTestRenderer as ReactTestRendererType } from "react-test-renderer"
declare type ReactTestInstance = $PropertyType<ReactTestRendererType, "root">;
declare type Predicate = (node: ReactTestInstance) => boolean;
declare type $ReturnType<Fn extends (...args: any) => any> = ReturnType<Fn>;
declare type ReactTestRendererJSON = $ReturnType<$2.create.toJSON>;
declare type ReactTestRendererJSON = $ReturnType<$ReturnType<typeof import("react-test-renderer")["create"]>["toJSON"]>;
declare function byClickable(): Predicate;
declare function byTestID(testID: string): Predicate;
declare function byTextMatching(regex: RegExp): Predicate;
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { ReactTestRenderer as ReactTestRendererType } from "react-test-renderer"
declare type ReactTestInstance = $PropertyType<ReactTestRendererType, "root">;
declare type Predicate = (node: ReactTestInstance) => boolean;
declare type $ReturnType<Fn extends (...args: any) => any> = ReturnType<Fn>;
declare type ReactTestRendererJSON = $ReturnType<$2.create.toJSON>;
declare type ReactTestRendererJSON = $ReturnType<$ReturnType<typeof import("react-test-renderer")["create"]>["toJSON"]>;
declare function byClickable(): Predicate;
declare function byTestID(testID: string): Predicate;
declare function byTextMatching(regex: RegExp): Predicate;
Expand Down
29 changes: 23 additions & 6 deletions workbench/overrides.ts
Expand Up @@ -150,15 +150,32 @@ const visitors: OverridesVisitors = {
},
},
},
// TODO: This should be fixed upstream in RN. This seems like simply broken upstream code.
"Libraries/Utilities/ReactNativeTestTools.d.ts": {
TSTypeAliasDeclaration: {
exit(path) {
if (path.node.id.name === "$ReturnType") {
const replacementDeclaration = ast`
declare type $ReturnType<Fn extends (...args: any) => any> = ReturnType<Fn>
` as t.TSTypeAliasDeclaration
path.replaceWith(replacementDeclaration)
path.skip()
switch (path.node.id.name) {
case "$ReturnType": {
const replacementDeclaration = ast`
declare type $ReturnType<Fn extends (...args: any) => any> = ReturnType<Fn>
` as t.TSTypeAliasDeclaration
path.replaceWith(replacementDeclaration)
path.skip()
break
}
case "ReactTestRendererJSON": {
const replacementDeclaration = ast`
declare type ReactTestRendererJSON =
$ReturnType<
$ReturnType<
typeof import("react-test-renderer")["create"]
>["toJSON"]
>
` as t.TSTypeAliasDeclaration
path.replaceWith(replacementDeclaration)
path.skip()
break
}
}
},
},
Expand Down

0 comments on commit 5e5ee95

Please sign in to comment.