Skip to content

Commit d3a1fcf

Browse files
authored
Merge pull request #28 from Yelp/fix_isResponseDictionary_flow_type_err
Fix typing errors from TS and the Flow codegen template
2 parents d84ec41 + 9a3da29 commit d3a1fcf

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ build: node_modules
1616
# Generate the .d.ts files
1717
node_modules/.bin/tsc --project tsconfig.json --checkJs false --emitDeclarationOnly || true
1818
# TODO: Loop through everything in the lib folder to create the flow types
19-
flowgen --add-flow-header lib/runtimeHelpers.d.ts --output-file lib/runtimeHelpers.js.flow
19+
yarn flowgen --add-flow-header lib/runtimeHelpers.d.ts --output-file lib/runtimeHelpers.js.flow
2020

2121
.PHONY: test
2222
test: build venv node_modules

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@
5656
"files": [
5757
"lib",
5858
"schema.json"
59-
]
59+
],
60+
"engines": {
61+
"node": ">=10"
62+
}
6063
}

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface GlobalConfig {
1616
resources: any;
1717
}
1818

19-
interface BatchResourceConfig {
19+
export interface BatchResourceConfig {
2020
isBatchResource: true;
2121
batchKey: string;
2222
newKey: string;
@@ -27,7 +27,7 @@ interface BatchResourceConfig {
2727
isResponseDictionary?: boolean;
2828
}
2929

30-
interface NonBatchResourceConfig {
30+
export interface NonBatchResourceConfig {
3131
isBatchResource: false;
3232
}
3333

src/genTypeFlow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const resourceReference = (resourcePath: ReadonlyArray<string>) => ['resources',
1414
*/
1515
export function getResourceTypeReference(resourceConfig: ResourceConfig, resourcePath: ReadonlyArray<string>) {
1616
function toPropertyTypePath(path: ReadonlyArray<string>): string {
17-
assert(path.length >= 1);
17+
assert(path.length >= 1, 'expected resource path to be a not empty array');
1818

1919
if (path.length === 1) {
2020
return path[0];
@@ -63,7 +63,7 @@ export function getLoaderTypeVal(resourceConfig: ResourceConfig, resourcePath: R
6363
>`;
6464

6565
if (resourceConfig.isBatchResource) {
66-
retVal = `$ElementType<${retVal}, 0>`;
66+
retVal = resourceConfig.isResponseDictionary ? `$Values<${retVal}>` : `$ElementType<${retVal}, 0>`;
6767
}
6868

6969
/**

src/implementation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ResourceConfig } from './config';
1+
import { ResourceConfig, BatchResourceConfig, NonBatchResourceConfig } from './config';
22
import assert from './assert';
33
import { getLoaderTypeKey, getLoaderTypeVal } from './genTypeFlow';
44

@@ -27,7 +27,7 @@ function getLoaderComment(resourceConfig: ResourceConfig, resourcePath: Readonly
2727
`;
2828
}
2929

30-
function getBatchLoader(resourceConfig: ResourceConfig, resourcePath: ReadonlyArray<string>) {
30+
function getBatchLoader(resourceConfig: BatchResourceConfig, resourcePath: ReadonlyArray<string>) {
3131
assert(
3232
resourceConfig.isBatchResource === true,
3333
`${errorPrefix(resourcePath)} Expected getBatchLoader to be called with a batch resource config`,
@@ -355,7 +355,7 @@ function getBatchLoader(resourceConfig: ResourceConfig, resourcePath: ReadonlyAr
355355
)`;
356356
}
357357

358-
function getNonBatchLoader(resourceConfig: ResourceConfig, resourcePath: ReadonlyArray<string>) {
358+
function getNonBatchLoader(resourceConfig: NonBatchResourceConfig, resourcePath: ReadonlyArray<string>) {
359359
assert(
360360
resourceConfig.isBatchResource === false,
361361
`${errorPrefix(resourcePath)} Expected getNonBatchLoader to be called with a non-batch endpoint config`,

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import codegen from './codegen';
88
import { getConfig } from './config';
99

1010
interface CLIArgs {
11-
config?: string;
12-
output?: string;
11+
config: string;
12+
output: string;
1313
}
1414

1515
function writeLoaders(args: CLIArgs) {
1616
const config = getConfig(args.config);
1717
const output = codegen(config);
1818

1919
assert(typeof args.config === 'string', 'expected args.config to be set!');
20+
assert(typeof args.output === 'string', 'expected args.output to be set!');
2021
fs.writeFileSync(args.output, output);
2122
}
2223

src/runtimeHelpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ export function sortByKeys<V>({
149149

150150
itemsMap.set(String(reorderResultsByValue), item);
151151
} else {
152-
// TODO: Work how to tell typescript item[prop] exists
152+
// @ts-ignore: TODO: Work how to tell typescript item[prop] exists
153153
invariant(item[prop] != null, `${errorPrefix(resourcePath)} Could not find property "${prop}" in item`);
154+
// @ts-ignore: TODO: Work how to tell typescript item[prop] exists
154155
itemsMap.set(String(item[prop]), item);
155156
}
156157
});

0 commit comments

Comments
 (0)