Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for TS2742 (workaround) #27

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,8 @@ generic parameter, such as `ErrorClass<[typeof plugin]>`.
They should only be used to type unknown error instances and classes, when no
variable nor [type inference](#type-inference) is available. For example, they
can be useful when [creating plugins](plugins.md#typescript).

## Known limitations and issues

For known limitations and issues related to TypeScript's current capabilities,
please see the comments in [src/main.d.ts](../src/main.d.ts).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

29 changes: 11 additions & 18 deletions src/main.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import type {
ErrorClass,
SpecificErrorClass,
ErrorSubclassCore,
} from './subclass/create.js'
import type { ErrorClass, SpecificErrorClass } from './subclass/create.js'
import type { CustomClass } from './subclass/custom.js'

export type { ErrorInstance } from './merge/cause.js'
export type { ClassOptions } from './options/class.js'
export type { InstanceOptions } from './options/instance.js'
export type { MethodOptions } from './options/method.js'
export type {
Info,
// Export required due to
// https://github.com/ehmicky/modern-errors/issues/18
CommonInfo,
} from './plugins/info/main.js'
export type { Info } from './plugins/info/main.js'
export type { Plugin } from './plugins/shape/main.js'
export type {
ErrorClass,
// Exports required due to
// https://github.com/ehmicky/modern-errors/issues/18
CustomClass,
ErrorSubclassCore,
}
export type { ErrorClass }

/**
* Top-level `ErrorClass`.
Expand Down Expand Up @@ -86,3 +71,11 @@ export default ModernError
// (e.g. `prepareStackTrace()`)
// - Plugins should not be allowed to define instance|static methods already
// defined by other plugins

// NOTE: The following exports are temporary workarounds for:
// - [modern-errors issue #18](https://github.com/ehmicky/modern-errors/issues/18)
// - [TypeScript issue #47663](https://github.com/microsoft/TypeScript/issues/47663)
export type { CommonInfo } from './plugins/info/main.js'
export type { CustomClass } from './subclass/custom.js'
export type { CreateSubclass, ErrorSubclassCore } from './subclass/create.js'
export type { NormalizeError } from './subclass/normalize.js'
7 changes: 7 additions & 0 deletions src/plugins/info/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import type { ErrorClass } from '../../subclass/create.js'

/**
* Properties shared by all `info` objects.
*
* @private This type is private and only exported as a temporary workaround
* for an open issue with TypeScript. It will be removed in a future release.
* See:
*
* - [modern-errors issue #18](https://github.com/ehmicky/modern-errors/issues/18)
* - [TypeScript issue #47663](https://github.com/microsoft/TypeScript/issues/47663)
*/
interface CommonInfo<Options = never> {
/**
Expand Down
14 changes: 14 additions & 0 deletions src/subclass/create.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import type { NormalizeError } from './normalize.js'

/**
* `ErrorClass.subclass()`
*
* @private This type is private and only exported as a temporary workaround
* for an open issue with TypeScript. It will be removed in a future release.
* See:
*
* - [modern-errors issue #18](https://github.com/ehmicky/modern-errors/issues/18)
* - [TypeScript issue #47663](https://github.com/microsoft/TypeScript/issues/47663)
*/
type CreateSubclass<
PluginsArg extends Plugins,
Expand All @@ -44,6 +51,13 @@ type CreateSubclass<

/**
* Non-dynamic members of error classes
*
* @private This type is private and only exported as a temporary workaround
* for an open issue with TypeScript. It will be removed in a future release.
* See:
*
* - [modern-errors issue #18](https://github.com/ehmicky/modern-errors/issues/18)
* - [TypeScript issue #47663](https://github.com/microsoft/TypeScript/issues/47663)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding those!

*/
interface ErrorSubclassCore<
PluginsArg extends Plugins,
Expand Down
7 changes: 7 additions & 0 deletions src/subclass/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import type { Plugins } from '../plugins/shape/main.js'

/**
* `custom` option
*
* @private This type is private and only exported as a temporary workaround
* for an open issue with TypeScript. It will be removed in a future release.
* See:
*
* - [modern-errors issue #18](https://github.com/ehmicky/modern-errors/issues/18)
* - [TypeScript issue #47663](https://github.com/microsoft/TypeScript/issues/47663)
*/
export interface CustomClass {
new (message: string, options?: InstanceOptions): Error
Expand Down
7 changes: 7 additions & 0 deletions src/subclass/normalize.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import type { CustomClass } from './custom.js'

/**
* `ErrorClass.normalize()`.
*
* @private This type is private and only exported as a temporary workaround
* for an open issue with TypeScript. It will be removed in a future release.
* See:
*
* - [modern-errors issue #18](https://github.com/ehmicky/modern-errors/issues/18)
* - [TypeScript issue #47663](https://github.com/microsoft/TypeScript/issues/47663)
*/
export type NormalizeError<
PluginsArg extends Plugins,
Expand Down