sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

[Documentation] logic error in ˋcontextˋ sample code #1112

Closed PopGoesTheWza closed 4 years ago

PopGoesTheWza commented 4 years ago

Describe the bug

In ˋREADME.mdˋ where the ˋcontextˋ option is described, sample code seems to have a logic error:

ˋˋˋjs if (!options.context && !options.context.token) { throw new Error('Token required'); } ˋˋˋ

Here !A && !B should be either !(A && B) or !A || !B.

Perhaps ˋ!options?.context?.tokenˋ would be valid too but awkward in the context of simple sample code.

Actual behavior

n.a.

Expected behavior

n.a.

Code to reproduce

Using Typescript, the code below is obviously wrong with the second term having the type ˋneverˋ

if (!options.context && !options.context.token) {
    throw new Error('Token required');
}

Checklist

szmarczak commented 4 years ago

Good catch!