{"record":{"id":"14ce21d412564616","repo":"denoland/deno","slug":"illegal-constructor-14ce21","errorCode":null,"errorMessage":"Illegal constructor","messagePattern":"Illegal constructor","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"runtime/js/10_permissions.js","lineNumber":100,"sourceCode":"  onchange = null;\n\n  /** @returns {Deno.PermissionState} */\n  get state() {\n    return this.#status.state;\n  }\n\n  /** @returns {boolean} */\n  get partial() {\n    return this.#status.partial;\n  }\n\n  /**\n   * @param {{ state: Deno.PermissionState, partial: boolean }} status\n   * @param {unknown} key\n   */\n  constructor(status = null, key = null) {\n    if (key != illegalConstructorKey) {\n      throw new TypeError(\"Illegal constructor\");\n    }\n    super();\n    this.#status = status;\n  }\n\n  /**\n   * @param {Event} event\n   * @returns {boolean}\n   */\n  dispatchEvent(event) {\n    let dispatched = super.dispatchEvent(event);\n    if (dispatched && this.onchange) {\n      FunctionPrototypeCall(this.onchange, this, event);\n      dispatched = !event.defaultPrevented;\n    }\n    return dispatched;\n  }\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/runtime/js/10_permissions.js#L82-L118","documentation":"Deno.PermissionStatus is exposed as a class but is not constructible: its constructor in runtime/js/10_permissions.js requires a private illegalConstructorKey symbol that only the permissions machinery holds. `new Deno.PermissionStatus()` throws TypeError('Illegal constructor'), matching the web-platform pattern where status objects are produced solely by query/request calls.","triggerScenarios":"`new Deno.PermissionStatus()`; `class X extends Deno.PermissionStatus { constructor() { super(); } }` (super() is invoked without the key); test code attempting to fabricate a status object.","commonSituations":"Unit tests that want a fixed { state, partial } shape without stubbing the API; code ported from environments where permission status is a plain data object.","solutions":["Obtain real instances from the factory API: `const status = await Deno.permissions.query({ name: 'read' })` (also querySync and request)","In tests, stub at the API level — replace Deno.permissions.query — instead of constructing status objects","If you only need the shape, define a plain type: `type StatusLike = { state: Deno.PermissionState; partial: boolean }`"],"exampleFix":"// before\nconst status = new Deno.PermissionStatus(); // TypeError: Illegal constructor\n\n// after\nconst status = await Deno.permissions.query({ name: 'read' });\nconsole.log(status.state, status.partial);","handlingStrategy":"validation","validationCode":null,"typeGuard":"const isPermissionStatus = (v) => v instanceof Deno.PermissionStatus;","tryCatchPattern":null,"preventionTips":["Treat Deno.PermissionStatus as factory-produced — only Deno.permissions.query/querySync/request may create it","In tests, stub Deno.permissions.query instead of fabricating status objects","Do not subclass web-platform classes with illegal constructors; compose plain types instead"],"tags":["permissions","illegal-constructor","typeerror","deno"],"backgroundTag":"illegal-constructor","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}