|
| 1 | +/** |
| 2 | + * @file Errors - ERR_INVALID_THIS |
| 3 | + * @module errnode/errors/ERR_INVALID_THIS |
| 4 | + * @see https://github.com/nodejs/node/blob/v22.8.0/lib/internal/errors.js#L1529 |
| 5 | + */ |
| 6 | + |
| 7 | +import E from '#e' |
| 8 | +import { codes } from '#src/enums' |
| 9 | +import type { NodeError, NodeErrorConstructor } from '#src/interfaces' |
| 10 | + |
| 11 | +/** |
| 12 | + * `ERR_INVALID_THIS` schema. |
| 13 | + * |
| 14 | + * @see {@linkcode NodeError} |
| 15 | + * @see https://nodejs.org/api/errors.html#err_invalid_this |
| 16 | + * |
| 17 | + * @extends {NodeError<codes.ERR_INVALID_THIS>} |
| 18 | + * @extends {TypeError} |
| 19 | + */ |
| 20 | +interface ErrInvalidThis extends NodeError<codes.ERR_INVALID_THIS>, TypeError {} |
| 21 | + |
| 22 | +/** |
| 23 | + * `ERR_INVALID_THIS` message arguments. |
| 24 | + */ |
| 25 | +type Args = [expected: string] |
| 26 | + |
| 27 | +/** |
| 28 | + * `ERR_INVALID_THIS` constructor. |
| 29 | + * |
| 30 | + * @see {@linkcode ErrInvalidThis} |
| 31 | + * @see {@linkcode NodeErrorConstructor} |
| 32 | + * |
| 33 | + * @extends {NodeErrorConstructor<ErrInvalidThis,Args>} |
| 34 | + */ |
| 35 | +interface ErrInvalidThisConstructor |
| 36 | + extends NodeErrorConstructor<ErrInvalidThis, Args> { |
| 37 | + /** |
| 38 | + * Create a new `ERR_INVALID_THIS` error. |
| 39 | + * |
| 40 | + * @see {@linkcode ErrInvalidThis} |
| 41 | + * |
| 42 | + * @param {string} expected |
| 43 | + * Expected type of `this` |
| 44 | + * @return {ErrInvalidThis} |
| 45 | + */ |
| 46 | + new (expected: string): ErrInvalidThis |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * `ERR_INVALID_THIS` model. |
| 51 | + * |
| 52 | + * Thrown when a Node.js API function is called with an incompatible `this` |
| 53 | + * value. |
| 54 | + * |
| 55 | + * @see {@linkcode ErrInvalidThisConstructor} |
| 56 | + * |
| 57 | + * @type {ErrInvalidThisConstructor} |
| 58 | + * |
| 59 | + * @class |
| 60 | + */ |
| 61 | +const ERR_INVALID_THIS: ErrInvalidThisConstructor = E( |
| 62 | + codes.ERR_INVALID_THIS, |
| 63 | + TypeError, |
| 64 | + 'Value of "this" must be of type %s' |
| 65 | +) |
| 66 | + |
| 67 | +export { |
| 68 | + ERR_INVALID_THIS as default, |
| 69 | + type ErrInvalidThis, |
| 70 | + type Args as ErrInvalidThisArgs, |
| 71 | + type ErrInvalidThisConstructor |
| 72 | +} |
0 commit comments