Skip to content

Commit

Permalink
Fix .toJSON() example
Browse files Browse the repository at this point in the history
Fixes #67
  • Loading branch information
sindresorhus committed Apr 3, 2022
1 parent 7e8be51 commit adc780d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
17 changes: 6 additions & 11 deletions index.d.ts
Expand Up @@ -74,21 +74,16 @@ console.log(serializeError(error));
```
import {serializeError} from 'serialize-error';
class ErrorWithToJSON extends Error {
constructor() {
super('🦄');
this.date = new Date();
}
const error = new Error('Unicorn');
error.horn = {
toJSON() {
return serializeError(this);
return 'x';
}
}
const error = new ErrorWithToJSON();
};
console.log(serializeError(error));
// => {date: '1970-01-01T00:00:00.000Z', message: '🦄', name, stack}
serializeError(error);
// => {horn: 'x', name, message, stack}
```
*/
export function serializeError<ErrorType>(error: ErrorType, options?: Options): ErrorType extends Primitive
Expand Down
17 changes: 6 additions & 11 deletions readme.md
Expand Up @@ -69,21 +69,16 @@ serializeError(error);
```js
import {serializeError} from 'serialize-error';

class ErrorWithToJSON extends Error {
constructor() {
super('🦄');
this.date = new Date();
}
const error = new Error('Unicorn');

error.horn = {
toJSON() {
return serializeError(this);
return 'x';
}
}

const error = new ErrorWithToJSON();
};

console.log(serializeError(error));
// => {date: '1970-01-01T00:00:00.000Z', message: '🦄', name, stack}
serializeError(error);
// => {horn: 'x', name, message, stack}
```

### deserializeError(value, options?)
Expand Down

0 comments on commit adc780d

Please sign in to comment.