Skip to content

Commit

Permalink
typescript-fetch-client: Try to autodetect default fetch rather tha…
Browse files Browse the repository at this point in the history
…n assuming a browser environment
  • Loading branch information
karlvr committed Sep 18, 2024
1 parent 838cbd5 commit d199524
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/fast-cheetahs-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@openapi-generator-plus/typescript-fetch-client-generator2": minor
"@openapi-generator-plus/typescript-fetch-client-generator": minor
---

Try to autodetect default `fetch` rather than assuming a browser environment
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if @root.includePolyfills}}
import "whatwg-fetch";
{{/if}}
export const defaultFetch = window.fetch;
export const defaultFetch = (typeof fetch !== "undefined" ? fetch : typeof window !== "undefined" && typeof window.fetch !== "undefined" ? window.fetch : undefined);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if @root.includePolyfills}}
import "whatwg-fetch";
{{/if}}
export const defaultFetch = window.fetch;
export const defaultFetch = (typeof fetch !== "undefined" ? fetch : typeof window !== "undefined" && typeof window.fetch !== "undefined" ? window.fetch : undefined);

0 comments on commit d199524

Please sign in to comment.