Skip to content

Disallow invalid options in fetch() and new Request() ​

💼 This rule is enabled in the ✅ recommended config.

fetch() throws a TypeError when the method is GET or HEAD and a body is provided.

Fail ​

js
const response = await fetch('/', {body: 'foo=bar'});
js
const request = new Request('/', {body: 'foo=bar'});
js
const response = await fetch('/', {method: 'GET', body: 'foo=bar'});
js
const request = new Request('/', {method: 'GET', body: 'foo=bar'});

Pass ​

js
const response = await fetch('/', {method: 'HEAD'});
js
const request = new Request('/', {method: 'HEAD'});
js
const response = await fetch('/', {method: 'POST', body: 'foo=bar'});
js
const request = new Request('/', {method: 'POST', body: 'foo=bar'});

Released under the Apache License 2.0.