1
1
import _ from 'lodash' ;
2
2
import prettier from 'prettier' ;
3
3
import { GlobalConfig , getResourcePaths } from './config' ;
4
- import { getLoaderType , getLoadersTypeMap , getResourceTypings } from './genTypeFlow ' ;
4
+ import { getLoaderType , getLoadersTypeMap , getResourceTypings } from './genType ' ;
5
5
import getLoaderImplementation from './implementation' ;
6
6
7
7
function getLoaders ( config : object , paths : Array < Array < string > > , current : Array < string > ) {
@@ -46,8 +46,6 @@ export default function codegen(
46
46
const { printResourceTypeImports, printResourcesType } = getResourceTypings ( config ) ;
47
47
48
48
const output = `
49
- // @flow strict-local
50
-
51
49
/**
52
50
* !!! THIS FILE IS AUTO-GENERATED. CHANGES MAY BE OVERWRITTEN !!!
53
51
*/
@@ -82,21 +80,22 @@ export default function codegen(
82
80
* ===============================
83
81
*/
84
82
85
- // https://github.com/facebook/flow/issues/7709#issuecomment-530501257
86
- type ExtractArg = <Arg, Ret>([Arg => Ret]) => Arg;
87
- type ExtractPromisedReturnValue<A> = <R>((...A) => Promise<R>) => R;
83
+ type PromisedReturnType<F extends (...args: any) => Promise<any>> =
84
+ F extends (...args: any) => Promise<infer R> ? R : never;
85
+
86
+ type Values<T> = T[keyof T];
88
87
89
- export type DataLoaderCodegenOptions = {|
88
+ export type DataLoaderCodegenOptions = {
90
89
errorHandler?: (
91
- resourcePath: $ReadOnlyArray <string>,
92
- // $FlowFixMe: We don't know what type the resource might throw, so we have to type error to "any" :(
90
+ resourcePath: ReadonlyArray <string>,
91
+ // We don't know what type the resource might throw, so we have to type error to "any" :(
93
92
error: any,
94
93
) => Promise<Error>,
95
- resourceMiddleware?: {|
96
- before?: <T>(resourcePath: $ReadOnlyArray <string>, resourceArgs: T) => Promise<T>,
97
- after?: <T>(resourcePath: $ReadOnlyArray <string>, response: T) => Promise<T>,
98
- | };
99
- | };
94
+ resourceMiddleware?: {
95
+ before?: <T>(resourcePath: ReadonlyArray <string>, resourceArgs: T) => Promise<T>,
96
+ after?: <T>(resourcePath: ReadonlyArray <string>, response: T) => Promise<T>,
97
+ };
98
+ };
100
99
101
100
/**
102
101
* ===============================
@@ -117,5 +116,5 @@ export default function codegen(
117
116
}
118
117
` ;
119
118
120
- return prettier . format ( output , { parser : 'babel' } ) ;
119
+ return prettier . format ( output , { parser : 'babel-ts ' } ) ;
121
120
}
0 commit comments