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 typedef #5
Fix typedef #5
Conversation
Since `module.exports` is actually overwritten by the function returned by `create(Error)`, this is not an es6-module compatible scenario. With this change, ```ts import * as ono from 'ono' throw ono(new Error('ono')) ``` and, perhaps more correctly ```ts import ono = require('ono') throw ono(new Error('ono')) ``` typecheck and generate correct code. Before this change, only ```ts import ono from 'ono' throw ono(new Error('ono')) ``` and ```ts import * as themodule from 'ono' throw themodule.default(new Error('ono')) ``` would typecheck, both of which would throw at runtime by trying to call `ono.default()` or `ono.default.syntax()`, etc...
Yup, that must be accurate. |
Interesting. I'm not experiencing the same behavior as you. I think it's because our TypeScript environments are different. I'm using TypeScript v3.0.1, and I have the Here's the behavior I'm seeing before your change... Without your change, and without
|
Thank you for that extensive testing, I never considered that exactly that setting does in depth. exports.a='a'
exports.b='b'
exports['default']='default' import { a }, def from 'module-name' ditto with module.exports = {a, b, default: 'default'} But if you assign something other than a plain object, eg: module.exports = 1 the only way to access it is to get the whole "module object", like this import * as wholeModule from 'one'
wholeModule === 1
Not sure what that does under the hood, but as a result, if your cjs module doesn't have TL;DR, roughly speaking:
{ a: exports.a, b:exports.b }
{ a: exports.a, b:exports.b, default: exports } |
Since
module.exports
is actually overwritten by the function returned bycreate(Error)
, this is not an es6-module compatible scenario.With this change,
and, perhaps more correctly
typecheck and generate correct code.
Before this change, only
and
would typecheck, both of which would throw at runtime by trying to call
ono.default()
orono.default.syntax()
, etc...