Skip to content

Commit 5febfea

Browse files
committed
fix(RequestInit): restrict body type based on method to improve type safety
1 parent ecc0f5e commit 5febfea

9 files changed

+11
-8
lines changed

baselines/dom.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ interface ReportingObserverOptions {
19531953

19541954
interface RequestInit {
19551955
/** A BodyInit object or null to set request's body. */
1956-
body?: BodyInit | null;
1956+
body?: 'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null | null;
19571957
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
19581958
cache?: RequestCache;
19591959
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */

baselines/serviceworker.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ interface ReportingObserverOptions {
560560

561561
interface RequestInit {
562562
/** A BodyInit object or null to set request's body. */
563-
body?: BodyInit | null;
563+
body?: 'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null | null;
564564
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
565565
cache?: RequestCache;
566566
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */

baselines/sharedworker.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ interface ReportingObserverOptions {
494494

495495
interface RequestInit {
496496
/** A BodyInit object or null to set request's body. */
497-
body?: BodyInit | null;
497+
body?: 'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null | null;
498498
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
499499
cache?: RequestCache;
500500
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */

baselines/ts5.5/dom.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ interface ReportingObserverOptions {
19531953

19541954
interface RequestInit {
19551955
/** A BodyInit object or null to set request's body. */
1956-
body?: BodyInit | null;
1956+
body?: 'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null | null;
19571957
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
19581958
cache?: RequestCache;
19591959
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */

baselines/ts5.5/serviceworker.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ interface ReportingObserverOptions {
560560

561561
interface RequestInit {
562562
/** A BodyInit object or null to set request's body. */
563-
body?: BodyInit | null;
563+
body?: 'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null | null;
564564
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
565565
cache?: RequestCache;
566566
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */

baselines/ts5.5/sharedworker.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ interface ReportingObserverOptions {
494494

495495
interface RequestInit {
496496
/** A BodyInit object or null to set request's body. */
497-
body?: BodyInit | null;
497+
body?: 'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null | null;
498498
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
499499
cache?: RequestCache;
500500
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */

baselines/ts5.5/webworker.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ interface ReportingObserverOptions {
702702

703703
interface RequestInit {
704704
/** A BodyInit object or null to set request's body. */
705-
body?: BodyInit | null;
705+
body?: 'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null | null;
706706
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
707707
cache?: RequestCache;
708708
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */

baselines/webworker.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ interface ReportingObserverOptions {
702702

703703
interface RequestInit {
704704
/** A BodyInit object or null to set request's body. */
705-
body?: BodyInit | null;
705+
body?: 'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null | null;
706706
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
707707
cache?: RequestCache;
708708
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */

inputfiles/overridingTypes.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,6 +3924,9 @@
39243924
"member": {
39253925
"window": {
39263926
"overrideType": "null"
3927+
},
3928+
"body": {
3929+
"overrideType": "'GET' | 'HEAD' extends this['method'] ? never : BodyInit | null"
39273930
}
39283931
}
39293932
}

0 commit comments

Comments
 (0)