Skip to content

Commit 0de68c9

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

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

codemods/safe-fetch.api.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
12+
if (!file.path.endsWith('runtime.ts')) return
13+
14+
const source = j(file.source)
15+
let returnStatement
16+
17+
return source
18+
.find(j.ClassMethod, { key: { name: 'fetchApi' } })
19+
.find(j.ReturnStatement)
20+
.forEach((r) => {
21+
returnStatement = r
22+
})
23+
.replaceWith(
24+
j.returnStatement(
25+
j.logicalExpression(
26+
'||',
27+
returnStatement.value.argument,
28+
j.identifier('fetch')
29+
)
30+
)
31+
)
32+
.toSource()
33+
}

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)