Skip to content

Commit 50eb1e4

Browse files
committed
refactor: stringifiable parameters
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 8c4a555 commit 50eb1e4

35 files changed

+502
-211
lines changed

.dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pathe
3939
pkgs
4040
preid
4141
shfmt
42+
stringifiable
4243
syscall
4344
syscodes
4445
unstub

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Universal API for creating [Node.js errors][errors]
3434
- [`NodeErrorConstructor<[T][, Args]>`](#nodeerrorconstructort-args)
3535
- [`NodeErrorMap`](#nodeerrormap)
3636
- [`NodeError<[T]>`](#nodeerrort)
37+
- [`Stringifiable`](#stringifiable)
3738
- [`SystemCode`](#systemcode)
3839
- [`SystemErrorMap`](#systemerrormap)
3940
- [Contribute](#contribute)
@@ -471,6 +472,15 @@ Node.js error object (TypeScript interface).
471472
- `toString` (`() => string`)
472473
— get a string representation of the error
473474

475+
### `Stringifiable`
476+
477+
A value with a `toString` method (TypeScript interface).
478+
479+
#### Properties
480+
481+
- `toString` (`() => string`)
482+
— get a string representation of the value
483+
474484
### `SystemCode`
475485

476486
Union of registered codes that can occur where a system error code is expected (TypeScript type).

src/errors/err-import-assertion-type-failed.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import E from '#e'
88
import { codes } from '#src/enums'
9-
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
9+
import type {
10+
NodeError,
11+
NodeErrorConstructor,
12+
Stringifiable
13+
} from '#src/interfaces'
1014

1115
/**
1216
* `ERR_IMPORT_ASSERTION_TYPE_FAILED` schema.
@@ -22,8 +26,10 @@ interface ErrImportAssertionTypeFailed
2226

2327
/**
2428
* `ERR_IMPORT_ASSERTION_TYPE_FAILED` message arguments.
29+
*
30+
* @see {@linkcode Stringifiable}
2531
*/
26-
type Args = [id: string, type: string]
32+
type Args = [id: Stringifiable, type: Stringifiable]
2733

2834
/**
2935
* `ERR_IMPORT_ASSERTION_TYPE_FAILED` constructor.
@@ -40,14 +46,15 @@ interface ErrImportAssertionTypeFailedConstructor
4046
* Create a new `ERR_IMPORT_ASSERTION_TYPE_FAILED` error.
4147
*
4248
* @see {@linkcode ErrImportAssertionTypeFailed}
49+
* @see {@linkcode Stringifiable}
4350
*
44-
* @param {string} id
45-
* Id of module that cannot be imported
46-
* @param {string} type
51+
* @param {Stringifiable} id
52+
* Module id
53+
* @param {Stringifiable} type
4754
* Invalid import assertion type
4855
* @return {ErrImportAssertionTypeFailed}
4956
*/
50-
new (id: string, type: string): ErrImportAssertionTypeFailed
57+
new (id: Stringifiable, type: Stringifiable): ErrImportAssertionTypeFailed
5158
}
5259

5360
/**

src/errors/err-import-assertion-type-missing.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import E from '#e'
88
import { codes } from '#src/enums'
9-
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
9+
import type {
10+
NodeError,
11+
NodeErrorConstructor,
12+
Stringifiable
13+
} from '#src/interfaces'
1014

1115
/**
1216
* `ERR_IMPORT_ASSERTION_TYPE_MISSING` schema.
@@ -22,8 +26,10 @@ interface ErrImportAssertionTypeMissing
2226

2327
/**
2428
* `ERR_IMPORT_ASSERTION_TYPE_MISSING` message arguments.
29+
*
30+
* @see {@linkcode Stringifiable}
2531
*/
26-
type Args = [id: string, type: string]
32+
type Args = [id: Stringifiable, type: Stringifiable]
2733

2834
/**
2935
* `ERR_IMPORT_ASSERTION_TYPE_MISSING` constructor.
@@ -40,14 +46,15 @@ interface ErrImportAssertionTypeMissingConstructor
4046
* Create a new `ERR_IMPORT_ASSERTION_TYPE_MISSING` error.
4147
*
4248
* @see {@linkcode ErrImportAssertionTypeMissing}
49+
* @see {@linkcode Stringifiable}
4350
*
44-
* @param {string} id
45-
* Id of module that cannot be imported
46-
* @param {string} type
51+
* @param {Stringifiable} id
52+
* Module id
53+
* @param {Stringifiable} type
4754
* Required import assertion type
4855
* @return {ErrImportAssertionTypeMissing}
4956
*/
50-
new (id: string, type: string): ErrImportAssertionTypeMissing
57+
new (id: Stringifiable, type: Stringifiable): ErrImportAssertionTypeMissing
5158
}
5259

5360
/**

src/errors/err-import-assertion-type-unsupported.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface ErrImportAssertionTypeUnsupported
2323
/**
2424
* `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED` message arguments.
2525
*/
26-
type Args = [type: string]
26+
type Args = [type: unknown]
2727

2828
/**
2929
* `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED` constructor.
@@ -41,11 +41,11 @@ interface ErrImportAssertionTypeUnsupportedConstructor
4141
*
4242
* @see {@linkcode ErrImportAssertionTypeUnsupported}
4343
*
44-
* @param {string} type
44+
* @param {unknown} type
4545
* Unsupported import assertion type
4646
* @return {ErrImportAssertionTypeUnsupported}
4747
*/
48-
new (type: string): ErrImportAssertionTypeUnsupported
48+
new (type: unknown): ErrImportAssertionTypeUnsupported
4949
}
5050

5151
/**

src/errors/err-import-attribute-missing.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import E from '#e'
88
import { codes } from '#src/enums'
9-
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
9+
import type {
10+
NodeError,
11+
NodeErrorConstructor,
12+
Stringifiable
13+
} from '#src/interfaces'
1014

1115
/**
1216
* `ERR_IMPORT_ATTRIBUTE_MISSING` schema.
@@ -22,8 +26,10 @@ interface ErrImportAttributeMissing
2226

2327
/**
2428
* `ERR_IMPORT_ATTRIBUTE_MISSING` message arguments.
29+
*
30+
* @see {@linkcode Stringifiable}
2531
*/
26-
type Args = [id: string, key: string, value: string]
32+
type Args = [id: Stringifiable, key: Stringifiable, value: Stringifiable]
2733

2834
/**
2935
* `ERR_IMPORT_ATTRIBUTE_MISSING` constructor.
@@ -40,16 +46,21 @@ interface ErrImportAttributeMissingConstructor
4046
* Create a new `ERR_IMPORT_ATTRIBUTE_MISSING` error.
4147
*
4248
* @see {@linkcode ErrImportAttributeMissing}
49+
* @see {@linkcode Stringifiable}
4350
*
44-
* @param {string} id
51+
* @param {Stringifiable} id
4552
* Module id
46-
* @param {string} key
53+
* @param {Stringifiable} key
4754
* The required import attribute key
48-
* @param {string} value
55+
* @param {Stringifiable} value
4956
* The required import attribute value
5057
* @return {ErrImportAttributeMissing}
5158
*/
52-
new (id: string, key: string, value: string): ErrImportAttributeMissing
59+
new (
60+
id: Stringifiable,
61+
key: Stringifiable,
62+
value: Stringifiable
63+
): ErrImportAttributeMissing
5364
}
5465

5566
/**

src/errors/err-import-attribute-type-incompatible.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import E from '#e'
88
import { codes } from '#src/enums'
9-
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
9+
import type {
10+
NodeError,
11+
NodeErrorConstructor,
12+
Stringifiable
13+
} from '#src/interfaces'
1014

1115
/**
1216
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` schema.
@@ -22,8 +26,10 @@ interface ErrImportAttributeTypeIncompatible
2226

2327
/**
2428
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` message arguments.
29+
*
30+
* @see {@linkcode Stringifiable}
2531
*/
26-
type Args = [id: string, type: string]
32+
type Args = [id: Stringifiable, type: Stringifiable]
2733

2834
/**
2935
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` constructor.
@@ -40,14 +46,18 @@ interface ErrImportAttributeTypeIncompatibleConstructor
4046
* Create a new `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` error.
4147
*
4248
* @see {@linkcode ErrImportAttributeTypeIncompatible}
49+
* @see {@linkcode Stringifiable}
4350
*
44-
* @param {string} id
51+
* @param {Stringifiable} id
4552
* Module id
46-
* @param {string} type
53+
* @param {Stringifiable} type
4754
* Specified type
4855
* @return {ErrImportAttributeTypeIncompatible}
4956
*/
50-
new (id: string, type: string): ErrImportAttributeTypeIncompatible
57+
new (
58+
id: Stringifiable,
59+
type: Stringifiable
60+
): ErrImportAttributeTypeIncompatible
5161
}
5262

5363
/**

src/errors/err-import-attribute-unsupported.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import E from '#e'
88
import { codes } from '#src/enums'
9-
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
9+
import type {
10+
NodeError,
11+
NodeErrorConstructor,
12+
Stringifiable
13+
} from '#src/interfaces'
1014

1115
/**
1216
* `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` schema.
@@ -22,8 +26,10 @@ interface ErrImportAttributeUnsupported
2226

2327
/**
2428
* `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` message arguments.
29+
*
30+
* @see {@linkcode Stringifiable}
2531
*/
26-
type Args = [key: string, value: string]
32+
type Args = [key: Stringifiable, value: unknown]
2733

2834
/**
2935
* `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` constructor.
@@ -40,14 +46,15 @@ interface ErrImportAttributeUnsupportedConstructor
4046
* Create a new `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` error.
4147
*
4248
* @see {@linkcode ErrImportAttributeUnsupported}
49+
* @see {@linkcode Stringifiable}
4350
*
44-
* @param {string} key
51+
* @param {Stringifiable} key
4552
* Import attribute key
46-
* @param {string} value
53+
* @param {unknown} value
4754
* Import attribute value
4855
* @return {ErrImportAttributeUnsupported}
4956
*/
50-
new (key: string, value: string): ErrImportAttributeUnsupported
57+
new (key: Stringifiable, value: unknown): ErrImportAttributeUnsupported
5158
}
5259

5360
/**

src/errors/err-incompatible-option-pair.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import E from '#e'
88
import { codes } from '#src/enums'
9-
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
9+
import type {
10+
NodeError,
11+
NodeErrorConstructor,
12+
Stringifiable
13+
} from '#src/interfaces'
1014

1115
/**
1216
* `ERR_INCOMPATIBLE_OPTION_PAIR` schema.
@@ -22,8 +26,10 @@ interface ErrIncompatibleOptionPair
2226

2327
/**
2428
* `ERR_INCOMPATIBLE_OPTION_PAIR` message arguments.
29+
*
30+
* @see {@linkcode Stringifiable}
2531
*/
26-
type Args = [option1: string, option2: string]
32+
type Args = [option1: Stringifiable, option2: Stringifiable]
2733

2834
/**
2935
* `ERR_INCOMPATIBLE_OPTION_PAIR` constructor.
@@ -40,14 +46,18 @@ interface ErrIncompatibleOptionPairConstructor
4046
* Create a new `ERR_INCOMPATIBLE_OPTION_PAIR` error.
4147
*
4248
* @see {@linkcode ErrIncompatibleOptionPair}
49+
* @see {@linkcode Stringifiable}
4350
*
44-
* @param {string} option1
51+
* @param {Stringifiable} option1
4552
* Option that cannot be used
46-
* @param {string} option2
53+
* @param {Stringifiable} option2
4754
* Option that is incompatible with `option1`
4855
* @return {ErrIncompatibleOptionPair}
4956
*/
50-
new (option1: string, option2: string): ErrIncompatibleOptionPair
57+
new (
58+
option1: Stringifiable,
59+
option2: Stringifiable
60+
): ErrIncompatibleOptionPair
5161
}
5262

5363
/**

src/errors/err-invalid-file-url-host.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import E from '#e'
88
import { codes } from '#src/enums'
9-
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
9+
import type {
10+
NodeError,
11+
NodeErrorConstructor,
12+
Stringifiable
13+
} from '#src/interfaces'
1014

1115
/**
1216
* `ERR_INVALID_FILE_URL_HOST` schema.
@@ -22,8 +26,10 @@ interface ErrInvalidFileUrlHost
2226

2327
/**
2428
* `ERR_INVALID_FILE_URL_HOST` message arguments.
29+
*
30+
* @see {@linkcode Stringifiable}
2531
*/
26-
type Args = [platform: string]
32+
type Args = [platform: Stringifiable]
2733

2834
/**
2935
* `ERR_INVALID_FILE_URL_HOST` constructor.
@@ -39,12 +45,13 @@ interface ErrInvalidFileUrlHostConstructor
3945
* Create a new `ERR_INVALID_FILE_URL_HOST` error.
4046
*
4147
* @see {@linkcode ErrInvalidFileUrlHost}
48+
* @see {@linkcode Stringifiable}
4249
*
43-
* @param {string} platform
50+
* @param {Stringifiable} platform
4451
* Platform invalid host was encountered on
4552
* @return {ErrInvalidFileUrlHost}
4653
*/
47-
new (platform: string): ErrInvalidFileUrlHost
54+
new (platform: Stringifiable): ErrInvalidFileUrlHost
4855
}
4956

5057
/**

0 commit comments

Comments
 (0)