Skip to content

Commit f164d8e

Browse files
committed
Fix types
1 parent edbc131 commit f164d8e

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

types/main.d.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ErrorObject } from 'error-serializer'
22

3-
import type { Info, ErrorInstance } from 'modern-errors'
3+
import type { Info } from 'modern-errors'
44

55
export type { ErrorObject }
66

@@ -20,8 +20,13 @@ declare const plugin: {
2020
* ([or YAML](https://github.com/ehmicky/error-serializer#custom-serializationparsing),
2121
* etc.). This is
2222
* [automatically called](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior)
23-
* by `JSON.stringify()`. All error properties
24-
* [are kept](https://github.com/ehmicky/error-serializer#additional-error-properties).
23+
* by `JSON.stringify()`.
24+
*
25+
* All
26+
* [error properties](https://github.com/ehmicky/error-serializer#additional-error-properties)
27+
* are kept.
28+
* [Plugin options](https://github.com/ehmicky/modern-errors#plugin-options)
29+
* are also preserved.
2530
*
2631
* @example
2732
* ```js
@@ -36,8 +41,10 @@ declare const plugin: {
3641
}
3742
staticMethods: {
3843
/**
39-
* Converts an error plain object back to an identical error instance.
40-
* The original error class is preserved.
44+
* If `value` is an error plain object, converts it to an error instance.
45+
* Otherwise, recurse over `value` and parse any nested error plain object.
46+
*
47+
* The original error classes are preserved.
4148
*
4249
* @example
4350
* ```js
@@ -48,10 +55,7 @@ declare const plugin: {
4855
* // filePath: '...'
4956
* ```
5057
*/
51-
parse: (
52-
info: Info['staticMethods'],
53-
errorObject: ErrorObject,
54-
) => ErrorInstance
58+
parse: (info: Info['staticMethods'], errorObject: unknown) => unknown
5559
}
5660
}
5761
export default plugin

types/main.test-d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expectType, expectError } from 'tsd'
22

3-
import ModernError, { ErrorInstance } from 'modern-errors'
3+
import ModernError from 'modern-errors'
44
import modernErrorsSerialize, { ErrorObject } from 'modern-errors-serialize'
55

66
const BaseError = ModernError.subclass('BaseError', {
@@ -21,5 +21,5 @@ expectError(BaseError.parse(errorObject, undefined))
2121
expectType<ErrorObject>(errorObject)
2222
expectType<string>(errorObject.name)
2323

24-
expectType<ErrorInstance>(BaseError.parse(errorObject))
25-
expectError(BaseError.parse({}))
24+
expectType<unknown>(BaseError.parse(errorObject))
25+
expectType<unknown>(BaseError.parse({ errorObject }))

0 commit comments

Comments
 (0)