Skip to content

Migrate to TypeScript#28

Merged
rekmarks merged 14 commits intomasterfrom
typescript
Nov 2, 2020
Merged

Migrate to TypeScript#28
rekmarks merged 14 commits intomasterfrom
typescript

Conversation

@rekmarks
Copy link
Member

@rekmarks rekmarks commented Nov 1, 2020

Migrates this package to TypeScript. In trying to fix the types for this package, which were always terrible and never worked out of the box, I just decided to go ahead with the TypeScript migration.

Bundles two behavioral changes:

  • ERROR_CODES export renamed to errorCodes
  • Fixes a bug where a truthy, non-string value could be provided as the message for error getters
    • An error will now be thrown instead

A major version bump of this package will follow.

Fixes #7

@rekmarks rekmarks requested a review from a team as a code owner November 1, 2020 03:14
@rekmarks rekmarks requested a review from brad-decker November 1, 2020 03:18
Comment on lines +209 to +211
if (message && typeof message !== 'string') {
throw new Error('Must specify string message.');
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Behavioral change 1 of 2:

It was previously possible to pass a truthy, non-string value as the message to error getters when using the object signature.

import { errorCodes } from './error-constants';

export {
errorCodes,
Copy link
Member Author

Choose a reason for hiding this comment

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

Behavioral change 2 of 2:

ERROR_CODES renamed to errorCodes.

Choose a reason for hiding this comment

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

Does this require the version bump to be a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! IMO, the first behavioral change arguably does too, even though it's a bug fix.

From the description:

A major version bump of this package will follow.

Choose a reason for hiding this comment

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

I can read, i swear

Copy link

@brad-decker brad-decker left a comment

Choose a reason for hiding this comment

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

A few suggestions to make this awesome work 1/10th of a step more awesome.

import { errorCodes } from './error-constants';

export {
errorCodes,

Choose a reason for hiding this comment

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

Does this require the version bump to be a breaking change?

@@ -0,0 +1,108 @@
import safeStringify from 'fast-safe-stringify';

export interface SerializedEthereumRpcError {

Choose a reason for hiding this comment

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

You should probably extends Error here to get the native types for an Error object. This will require some changes (stack is string | undefined, name is required)

Copy link
Member Author

Choose a reason for hiding this comment

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

I intentionally didn't extend Error for these types, because they're intended to follow the JSON-RPC spec, not the native JavaScript error.

@rekmarks rekmarks merged commit 84e90eb into master Nov 2, 2020
@rekmarks rekmarks deleted the typescript branch November 2, 2020 23:45
This was referenced Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate to TypeScript

2 participants