Skip to content

Commit 6bf845b

Browse files
committed
Improve types
1 parent 243bbad commit 6bf845b

File tree

1 file changed

+66
-21
lines changed

1 file changed

+66
-21
lines changed

types/main.test-d.ts

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import modernErrors from 'modern-errors'
1+
import ModernError from 'modern-errors'
22
import plugin, { Options, HttpResponse } from 'modern-errors-http'
33
import {
44
expectType,
@@ -7,71 +7,116 @@ import {
77
expectError,
88
} from 'tsd'
99

10-
const BaseError = modernErrors([plugin])
11-
const error = new BaseError('', { cause: '' })
10+
const BaseError = ModernError.subclass('BaseError', { plugins: [plugin] })
11+
const error = new BaseError('')
1212
const httpResponse = error.httpResponse()
1313

14-
modernErrors([plugin], { http: {} })
14+
ModernError.subclass('TestError', { plugins: [plugin], http: {} })
1515
error.httpResponse({})
1616
expectAssignable<Options>({})
1717
expectError(error.httpResponse(undefined))
1818
expectNotAssignable<Options>(undefined)
19-
expectError(modernErrors([plugin], { http: true }))
19+
expectError(
20+
ModernError.subclass('TestError', { plugins: [plugin], http: true }),
21+
)
2022
expectError(error.httpResponse(true))
2123
expectNotAssignable<Options>(true)
22-
expectError(modernErrors([plugin], { http: { unknown: true } }))
24+
expectError(
25+
ModernError.subclass('TestError', {
26+
plugins: [plugin],
27+
http: { unknown: true },
28+
}),
29+
)
2330
expectError(error.httpResponse({ unknown: true }))
2431
expectNotAssignable<Options>({ unknown: true })
2532

26-
modernErrors([plugin], { http: { type: '' } })
33+
ModernError.subclass('TestError', { plugins: [plugin], http: { type: '' } })
2734
error.httpResponse({ type: '' })
2835
expectAssignable<Options>({ type: '' })
29-
expectError(modernErrors([plugin], { http: { type: true } }))
36+
expectError(
37+
ModernError.subclass('TestError', {
38+
plugins: [plugin],
39+
http: { type: true },
40+
}),
41+
)
3042
expectError(error.httpResponse({ type: true }))
3143
expectNotAssignable<Options>({ type: true })
3244

33-
modernErrors([plugin], { http: { status: 200 } })
45+
ModernError.subclass('TestError', { plugins: [plugin], http: { status: 200 } })
3446
error.httpResponse({ status: 200 })
3547
expectAssignable<Options>({ status: 200 })
36-
expectError(modernErrors([plugin], { http: { status: true } }))
48+
expectError(
49+
ModernError.subclass('TestError', {
50+
plugins: [plugin],
51+
http: { status: true },
52+
}),
53+
)
3754
expectError(error.httpResponse({ status: true }))
3855
expectNotAssignable<Options>({ status: true })
3956

40-
modernErrors([plugin], { http: { title: '' } })
57+
ModernError.subclass('TestError', { plugins: [plugin], http: { title: '' } })
4158
error.httpResponse({ title: '' })
4259
expectAssignable<Options>({ title: '' })
43-
expectError(modernErrors([plugin], { http: { title: true } }))
60+
expectError(
61+
ModernError.subclass('TestError', {
62+
plugins: [plugin],
63+
http: { title: true },
64+
}),
65+
)
4466
expectError(error.httpResponse({ title: true }))
4567
expectNotAssignable<Options>({ title: true })
4668

47-
modernErrors([plugin], { http: { detail: '' } })
69+
ModernError.subclass('TestError', { plugins: [plugin], http: { detail: '' } })
4870
error.httpResponse({ detail: '' })
4971
expectAssignable<Options>({ detail: '' })
50-
expectError(modernErrors([plugin], { http: { detail: true } }))
72+
expectError(
73+
ModernError.subclass('TestError', {
74+
plugins: [plugin],
75+
http: { detail: true },
76+
}),
77+
)
5178
expectError(error.httpResponse({ detail: true }))
5279
expectNotAssignable<Options>({ detail: true })
5380

54-
modernErrors([plugin], { http: { instance: '' } })
81+
ModernError.subclass('TestError', { plugins: [plugin], http: { instance: '' } })
5582
error.httpResponse({ instance: '' })
5683
expectAssignable<Options>({ instance: '' })
57-
expectError(modernErrors([plugin], { http: { instance: true } }))
84+
expectError(
85+
ModernError.subclass('TestError', {
86+
plugins: [plugin],
87+
http: { instance: true },
88+
}),
89+
)
5890
expectError(error.httpResponse({ instance: true }))
5991
expectNotAssignable<Options>({ instance: true })
6092

61-
modernErrors([plugin], { http: { stack: '' } })
93+
ModernError.subclass('TestError', { plugins: [plugin], http: { stack: '' } })
6294
error.httpResponse({ stack: '' })
6395
expectAssignable<Options>({ stack: '' })
64-
expectError(modernErrors([plugin], { http: { stack: true } }))
96+
expectError(
97+
ModernError.subclass('TestError', {
98+
plugins: [plugin],
99+
http: { stack: true },
100+
}),
101+
)
65102
expectError(error.httpResponse({ stack: true }))
66103
expectNotAssignable<Options>({ stack: true })
67104

68-
modernErrors([plugin], { http: { extra: {} } })
105+
ModernError.subclass('TestError', { plugins: [plugin], http: { extra: {} } })
69106
error.httpResponse({ extra: {} })
70107
expectAssignable<Options>({ extra: {} })
71-
modernErrors([plugin], { http: { extra: { prop: true } } })
108+
ModernError.subclass('TestError', {
109+
plugins: [plugin],
110+
http: { extra: { prop: true } },
111+
})
72112
error.httpResponse({ extra: { prop: true } })
73113
expectAssignable<Options>({ extra: { prop: true } })
74-
expectError(modernErrors([plugin], { http: { extra: true } }))
114+
expectError(
115+
ModernError.subclass('TestError', {
116+
plugins: [plugin],
117+
http: { extra: true },
118+
}),
119+
)
75120
expectError(error.httpResponse({ extra: true }))
76121
expectNotAssignable<Options>({ extra: true })
77122

0 commit comments

Comments
 (0)