-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmain.test-d.ts
More file actions
47 lines (42 loc) · 1.56 KB
/
Copy pathmain.test-d.ts
File metadata and controls
47 lines (42 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import ModernError from 'modern-errors'
import modernErrorsExample, { type Options } from 'modern-errors-example'
import { expectType, expectAssignable, expectNotAssignable } from 'tsd'
// Check the plugin shape by passing it to `modernErrors()`
const BaseError = ModernError.subclass('BaseError', {
plugins: [modernErrorsExample],
})
const error = new BaseError('')
// Check `plugin.properties()`
expectType<string>(error.exampleProp)
// @ts-expect-error
error.unknownProp
// Check `plugin.instanceMethods`
expectType<string>(BaseError.exampleMethod(error, 'validArgument'))
// @ts-expect-error
BaseError.exampleMethod(error, 'invalidArgument')
// Check `plugin.staticMethods`
expectType<string>(BaseError.staticMethod('validArgument'))
// @ts-expect-error
BaseError.staticMethod('invalidArgument')
// Check `plugin.getOptions()`, `plugin.isOptions()` and `plugin.name`
ModernError.subclass('TestError', {
plugins: [modernErrorsExample],
exampleOption: 'validOption',
})
BaseError.exampleMethod(error, 'validArgument', {
exampleOption: 'validOption',
})
BaseError.staticMethod('validArgument', { exampleOption: 'validOption' })
expectAssignable<Options>({ exampleOption: 'validOption' })
// @ts-expect-error
ModernError.subclass('TestError', {
plugins: [modernErrorsExample],
exampleOption: 'invalidOption',
})
// @ts-expect-error
BaseError.exampleMethod(error, 'validArgument', {
exampleOption: 'invalidOption',
})
// @ts-expect-error
BaseError.staticMethod('validArgument', { exampleOption: 'invalidOption' })
expectNotAssignable<Options>({ exampleOption: 'invalidOption' })