Skip to content

Commit c53e4f4

Browse files
committed
Fix last type error by patching fetch type
1 parent f27ebbd commit c53e4f4

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

codemods/patch-to-json-type-failures.api.js

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const ToJSONFunctionFilter = (funcDeclaration) => {
1818
*/
1919
export default function transformer(file, api) {
2020
const j = api.jscodeshift
21-
2221
const source = j(file.source)
2322
const dir = path.dirname(file.path)
2423
const filename = path.basename(file.path, '.ts')

codemods/safe-fetch.api.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* This codemod patches the open-api's generated `runtime.ts` file
3+
* to ensure the member property `get fetchApi` returns a valid fetch
4+
* function.
5+
*
6+
* @param {import('jscodeshift').FileInfo} file
7+
* @param {import('jscodeshift').API} api
8+
*/
9+
export default function transformer(file, api) {
10+
const j = api.jscodeshift
11+
const source = j(file.source)
12+
let returnStatement
13+
14+
if (!file.path.endsWith('runtime.ts')) return
15+
16+
return source
17+
.find(j.ClassMethod, { key: { name: 'fetchApi' } })
18+
.find(j.ReturnStatement)
19+
.forEach((r) => {
20+
returnStatement = r
21+
})
22+
.replaceWith(
23+
j.returnStatement(
24+
j.logicalExpression(
25+
'||',
26+
returnStatement.value.argument,
27+
j.identifier('fetch')
28+
)
29+
)
30+
)
31+
.toSource()
32+
}

libs/api/__generated__/runtime.ts

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)