{"id":"08306f103eee00ec","repo":"sindresorhus/is","slug":"expected-value-which-is-url-received-value-of-t","errorCode":null,"errorMessage":"Expected value which is `URL`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `URL`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1956,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('Uint8Array', value));\n\t}\n}\n\nexport function assertUint8ClampedArray(value: unknown, message?: string): asserts value is Uint8ClampedArray {\n\tif (!isUint8ClampedArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint8ClampedArray', value));\n\t}\n}\n\nexport function assertUndefined(value: unknown, message?: string): asserts value is undefined {\n\tif (!isUndefined(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('undefined', value));\n\t}\n}\n\nexport function assertUrlInstance(value: unknown, message?: string): asserts value is URL {\n\tif (!isUrlInstance(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('URL', value));\n\t}\n}\n\n// eslint-disable-next-line unicorn/prevent-abbreviations\nexport function assertUrlSearchParams(value: unknown, message?: string): asserts value is URLSearchParams {\n\tif (!isUrlSearchParams(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('URLSearchParams', value));\n\t}\n}\n\nexport function assertUrlString(value: unknown, message?: string): asserts value is UrlString {\n\tif (!isUrlString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('string with a URL', value));\n\t}\n}\n\nexport function assertValidDate(value: unknown, message?: string): asserts value is Date {\n\tif (!isValidDate(value)) {","sourceCodeStart":1938,"sourceCodeEnd":1974,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1938-L1974","documentation":"Thrown by `assertUrlInstance()` in @sindresorhus/is when the value is not a `URL` object instance. It checks for the URL class specifically — a valid URL *string* still fails, because strings are covered by the separate `urlString` guard.","triggerScenarios":"`assert.urlInstance(value)` called with a string like \"https://example.com\", a Node legacy `url.parse()` result, a Location object, or a plain object with href/host fields.","commonSituations":"Config values and env vars are strings and get passed straight to code expecting a URL object; mixing Node's legacy `url` module output with WHATWG URL; JSON-deserialized data where a URL became its href string.","solutions":["Wrap strings: `new URL(value)` before asserting/using.","If a URL string is what you actually accept, use `assert.urlString(value)` instead.","At API boundaries accept `string | URL` and normalize once: `const url = value instanceof URL ? value : new URL(value)`."],"exampleFix":"// before\nassert.urlInstance(process.env.API_URL);\n// after\nassert.urlString(process.env.API_URL);\nconst url = new URL(process.env.API_URL);","handlingStrategy":"type-guard","validationCode":"if (!is.urlInstance(value)) {\n  value = new URL(String(value)); // may itself throw on invalid URL strings\n}","typeGuard":"if (is.urlInstance(value)) {\n  // value is URL here\n}","tryCatchPattern":"try {\n  assert.urlInstance(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* got a string or other non-URL */ }\n  throw error;\n}","preventionTips":["A URL string does not pass is.urlInstance() — construct new URL(str) first","Use is.urlString() when you want to accept strings and urlInstance for objects","Normalize to a URL instance once at the boundary and pass the instance around"],"tags":["typescript","type-assertion","url"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}