Comments (4)
Also, in the future, prefer using a permalink when linking to code. So instead of
https://github.com/sindresorhus/serialize-error/blob/main/index.js#L160
You should use:
https://github.com/sindresorhus/serialize-error/blob/2a77169cae632802b75c9962b8ae9a482c978ae2/index.js#L160
To get this link:
from serialize-error.
Should the type of return value must be also function as well?
No...
If we still want to convert function value to string,
According to this test, yes we do.
The type definition for input & return value should be
any
orunknown
since they don't share the same type.
There's nothing wrong with input type and return type not sharing the same type.
from serialize-error.
There's nothing wrong with input type and return type not sharing the same type.
@papb What I wanted to say is that the current type definition is wrong
https://github.com/sindresorhus/serialize-error/blob/main/index.d.ts#L108
Type definition is enforcing that the return value should have the same type of the input, while we convert function inputs to string
from serialize-error.
Type definition is enforcing that the return value should have the same type of the input
That is correct. serializeError
returns the same value if it's not an object
and not a function
Lines 141 to 166 in 2a77169
The logic is simply:
- if it's an object, return an object
- if it's a function, return a string
- if it's anything else, return it as is
The return is never unknown
. Even if it is, we know it's Input
, so we return it as such.
from serialize-error.
Related Issues (20)
- Error: Cannot read property 'pipe' of null
- Version 9.1.1 with CRA default Babel config gives "Module parse failed" HOT 1
- Jest encountered an unexpected token HOT 1
- Optionally ignore `toJSON` HOT 2
- `toJSON` example is confusing
- Handle custom error constructors with incompatible signatures
- Nested errors are still not serialized
- Unknown object type "asyncfunction" HOT 3
- `deserializeError` serializes/destroys properties unnecessarily HOT 1
- Wrong typescript declaration for errorConstructors HOT 6
- Jest encounters `SyntaxError: Cannot use import statement outside a module` while trying to test code that uses `serialize-error` HOT 8
- If string is passed as unknown, the value returned from serializeError is badly typed as ErrorObject HOT 1
- Error require of ES Module not supported HOT 21
- Visibility of undefined values in the objects
- Enumerable properties are made non-enumerable
- Keep old versions of the lib on a separate branch HOT 1
- `option` to treat undefined as null HOT 1
- Received error object is not extensible when calling serialize error
- ERR_REQUIRE_ESM HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serialize-error.