diff --git a/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts b/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts index 1e8a8c3b18..1e9a2395a4 100644 --- a/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts +++ b/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts @@ -1,129 +1,93 @@ import { createBatchResolver, ResolverFunction } from "graphql-resolve-batch"; -// Test cases split up in namespaces to test different type inference scenarios. - -namespace WithSourceAndResult { - interface SomeTestSource { - someSourceProp: string; - } - - interface SomeTestResult { - someTestResultProp: string; - } - - const verify = createBatchResolver( - (sources, _, __) => { - return sources.map(source => { - const res: SomeTestResult = { - someTestResultProp: "" - }; - - return res; - }); - } - ); +interface SomeTestSource { + someSourceProp: string; } -namespace WithSourceAndResultAsPromise { - interface SomeTestSource { - someSourceProp: string; - } - - interface SomeTestResult { - someTestResultProp: string; - } - - const verify = createBatchResolver( - (sources, _, __) => { - // $ExpectType ReadonlyArray - const verifySources = sources; - - return sources.map(source => { - return new Promise(resolve => { - const res: SomeTestResult = { - someTestResultProp: "" - }; - - resolve(res); - }); - }); - } - ); +interface SomeTestArgs { + someArg: string; } -namespace WithSourceAndArgsAndResult { - interface SomeTestSource { - someSourceProp: string; - } +interface SomeTestContext { + someContextProp: string; +} - interface SomeTestArgs { - someArg: string; - } +interface SomeTestResult { + someTestResultProp: string; +} - interface SomeTestResult { - someTestResultProp: string; - } +const withSourceAndResultTyped = createBatchResolver< + SomeTestSource, + SomeTestResult +>((sources, _, __) => { + return sources.map(source => { + const res: SomeTestResult = { + someTestResultProp: "" + }; - const verify = createBatchResolver< - SomeTestSource, - SomeTestResult, - SomeTestArgs - >((sources, args, _) => { - // $ExpectType ReadonlyArray - const verifySources = sources; - // $ExpectType string - const verifyArgs = args.someArg; + return res; + }); +}); - return sources.map(source => { - return new Promise(resolve => { - const res: SomeTestResult = { - someTestResultProp: "" - }; +const withSourceAndResultTypedAsPromise = createBatchResolver< + SomeTestSource, + SomeTestResult +>((sources, _, __) => { + // $ExpectType ReadonlyArray + const verifySources = sources; - resolve(res); - }); + return sources.map(source => { + return new Promise(resolve => { + const res: SomeTestResult = { + someTestResultProp: "" + }; + + resolve(res); }); }); -} +}); -namespace WithSourceAndArgsAndContextAndResult { - interface SomeTestSource { - someSourceProp: string; - } +const withSourceAndArgsAndResultTyped = createBatchResolver< + SomeTestSource, + SomeTestResult, + SomeTestArgs +>((sources, args, _) => { + // $ExpectType ReadonlyArray + const verifySources = sources; + // $ExpectType string + const verifyArgs = args.someArg; - interface SomeTestArgs { - someArg: string; - } + return sources.map(source => { + return new Promise(resolve => { + const res: SomeTestResult = { + someTestResultProp: "" + }; - interface SomeTestContext { - someContextProp: string; - } - - interface SomeTestResult { - someTestResultProp: string; - } - - const verify = createBatchResolver< - SomeTestSource, - SomeTestResult, - SomeTestArgs, - SomeTestContext - >((sources, args, context) => { - // $ExpectType ReadonlyArray - const verifySources = sources; - // $ExpectType string - const verifyArgs = args.someArg; - // $ExpectType string - const verifyContext = context.someContextProp; - - return sources.map(source => { - return new Promise(resolve => { - const res: SomeTestResult = { - someTestResultProp: "" - }; - - resolve(res); - }); + resolve(res); }); }); -} +}); + +const withSourceAndArgsAndContextTyped = createBatchResolver< + SomeTestSource, + SomeTestResult, + SomeTestArgs, + SomeTestContext +>((sources, args, context) => { + // $ExpectType ReadonlyArray + const verifySources = sources; + // $ExpectType string + const verifyArgs = args.someArg; + // $ExpectType string + const verifyContext = context.someContextProp; + + return sources.map(source => { + return new Promise(resolve => { + const res: SomeTestResult = { + someTestResultProp: "" + }; + + resolve(res); + }); + }); +}); diff --git a/types/graphql-resolve-batch/index.d.ts b/types/graphql-resolve-batch/index.d.ts index 3fd9e1242b..46f354f7b7 100644 --- a/types/graphql-resolve-batch/index.d.ts +++ b/types/graphql-resolve-batch/index.d.ts @@ -23,4 +23,4 @@ export type BatchResolveFunction = ( sources: ReadonlyArray, args: TArgs, context: TContext -) => TReturn[] | Promise[]; +) => TReturn[] | Array>; diff --git a/types/graphql-resolve-batch/tslint.json b/types/graphql-resolve-batch/tslint.json index fa856c9e87..f93cf8562a 100644 --- a/types/graphql-resolve-batch/tslint.json +++ b/types/graphql-resolve-batch/tslint.json @@ -1,7 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "no-namespace": false, - "array-type": [true, "array"] - } + "extends": "dtslint/dt.json" }