{"id":"e561858219832b6e","repo":"sindresorhus/got","slug":"invalid-responsetype-option-value-as-string","errorCode":null,"errorMessage":"Invalid `responseType` option: ${value as string}","messagePattern":"Invalid `responseType` option: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/core/options.ts","lineNumber":3317,"sourceCode":"\t// This\n\tconst body = await got(url).json();\n\n\t// is semantically the same as this\n\tconst body = await got(url, {responseType: 'json', resolveBodyOnly: true});\n\t```\n\t*/\n\tget responseType(): ResponseType {\n\t\treturn this.#internals.responseType;\n\t}\n\n\tset responseType(value: ResponseType) {\n\t\tif (value === undefined) {\n\t\t\tthis.#internals.responseType = 'text';\n\t\t\treturn;\n\t\t}\n\n\t\tif (value !== 'text' && value !== 'buffer' && value !== 'json') {\n\t\t\tthrow new Error(`Invalid \\`responseType\\` option: ${value as string}`);\n\t\t}\n\n\t\tthis.#internals.responseType = value;\n\t}\n\n\tget pagination(): PaginationOptions<unknown, unknown> {\n\t\treturn this.#internals.pagination;\n\t}\n\n\tset pagination(value: PaginationOptions<unknown, unknown>) {\n\t\tassert.object(value);\n\n\t\tif (this.#merging) {\n\t\t\tsafeObjectAssign(this.#internals.pagination, value);\n\t\t} else {\n\t\t\tthis.#internals.pagination = value;\n\t\t}\n\t}","sourceCodeStart":3299,"sourceCodeEnd":3335,"githubUrl":"https://github.com/sindresorhus/got/blob/e3924aa1e53a6ca3eb93a43618ce532442a89b40/source/core/options.ts#L3299-L3335","documentation":"Thrown by the `responseType` setter when the value is anything other than `'text'`, `'buffer'`, or `'json'` (or `undefined`, which defaults to `'text'`). The response type drives how Got parses the body, so an unrecognized value would leave parsing undefined and is rejected up front.","triggerScenarios":"Calling `got(url, {responseType: 'arraybuffer'})`, `{responseType: 'stream'}` (use `got.stream(url)` instead), `{responseType: 'raw'}`, or any value outside the three supported strings.","commonSituations":"Using fetch/axios response type names (`arraybuffer`, `blob`, `document`); typos; passing a value from a config file as a string.","solutions":["Use one of `'text'`, `'buffer'`, or `'json'`.","For streaming responses call `got.stream(url)` instead of setting `responseType`.","For raw bytes use `'buffer'` (returns a `Uint8Array`)."],"exampleFix":"// before\nconst data = await got(url, {responseType: 'arraybuffer'});\n// after\nconst data = await got(url, {responseType: 'buffer'});","handlingStrategy":"type-guard","validationCode":"const validResponseTypes = new Set(['text','buffer','json','undefined']);\nfunction validateResponseType(value) {\n  if (value !== undefined && !validResponseTypes.has(value)) {\n    throw new Error(`responseType must be 'text', 'buffer', or 'json'; got ${value}`);\n  }\n}","typeGuard":"function isResponseType(v: unknown): v is 'text' | 'buffer' | 'json' | undefined {\n  return v === undefined || v === 'text' || v === 'buffer' || v === 'json';\n}","tryCatchPattern":null,"preventionTips":["Map fetch/axios names: `arraybuffer`/`blob` -> `'buffer'`; streaming -> `got.stream()`.","Use the `ResponseType` type from Got to catch bad values at compile time."],"tags":["options","response-type","validation","config"],"analyzedSha":"e3924aa1e53a6ca3eb93a43618ce532442a89b40","analyzedAt":"2026-08-03T19:22:24.770Z","schemaVersion":2}