-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
import * as alias syntax doesn't work with export = function unless merged with namespace #5073
Comments
there is no way in an ES6 module to achieve this. the parallel in an ES6 module world is to |
Without this, there will be `Module '"koa-bodyparser"' resolves to a non-module entity and cannot be imported using this construct. (2497)` error This solution is found (here)[microsoft/TypeScript#5073]. koa-json's `.d.ts` file has such namespace.
Without this, there will be `Module '"koa-bodyparser"' resolves to a non-module entity and cannot be imported using this construct. (2497)` error This solution is found (here)[microsoft/TypeScript#5073]. koa-json's `.d.ts` file has such namespace.
Without this, there will be `Module '"koa-bodyparser"' resolves to a non-module entity and cannot be imported using this construct. (2497)` error This solution is found (here)[microsoft/TypeScript#5073]. koa-json's `.d.ts` file has such namespace.
* added svgRendering property to Html2CanvasOptions interface * added an empty namespace in koa-bodyparser.d.ts (#8979) Without this, there will be `Module '"koa-bodyparser"' resolves to a non-module entity and cannot be imported using this construct. (2497)` error This solution is found (here)[microsoft/TypeScript#5073]. koa-json's `.d.ts` file has such namespace. * Missing locale functions and types
* Boostrap -> Bootstrap * Allow ES6 import syntax for wolfy87-eventemitter.d.ts See microsoft/TypeScript#5073
Per microsoft/TypeScript#5073, closed as `By Design` by @mhegazy, we need to merge a namespace with the export when using `export =`, otherwise `import *` must fail.
Per microsoft/TypeScript#5073, closed as `By Design` by @mhegazy, we need to export a namespace for `import *` to work, else `TS2497`. That clashes with the `export = ClassName` pattern unless you also merge in a namespace, e.g. with `namespace ClassName {}`.
Without the hack, TS code cannot target es6 if it consumes cjs module. With Babel, JS user is doing |
I still can't tell if this was ever intended behavior or not (that using the namespace allows this to pass typecheck), or just a happy accident that now too many people rely on to change.n It seems an empty namespace gets SymbolType NamespaceModule (1024) and the checker looks for the merged symbol. So basically
is what I think is happening? The PR that added module support #2242 explicitly mentions:
But I don't understand what typescript considers a non-module entity. The actual line in checker that flags these errors is: So I can get away with pretty confusing stuff like:
Which passes compilation fine as with Is a module entity related to https://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects, which is what the es6 grammar specifies is the type of |
Improving export (microsoft/TypeScript#5073)
So, is this the hack? declare module 'nedb-core' {
class Datastore {
constructor(options?: {})
}
namespace Datastore {
}
export = Datastore
} |
@qm3ster I think so.. I don't like the consistency here..have you found any solution for this??? |
@LouisWayne well, the reason a hack might be the best we can do is because we are trying to ES6-import something that could never have been ES6-exported. |
in issue BrasilAPI#112, we saw the problem with angular 5. in my tests, i install angular 5 and rollback the definition without workarround solved for default function microsoft/TypeScript#5073 and this back work, i think this worked because typescript can have a fix in recent version.
Apparently import * as alias syntax does not work with export = function: microsoft/TypeScript#5073
* Prefer a namespace over declare module Apparently import * as alias syntax does not work with export = function: microsoft/TypeScript#5073 * TslintOptions already includes format
With import x from 'cjs'
// instead of
import * as x from 'cjs' |
Thanks! |
Can't be included via
import * as f from "foo";
.(
test.ts(1,20): error TS2497: Module '"foo"' resolves to a non-module entity and cannot be imported using this construct.
)Whereas
Can be. The distinction seems artificial.
The text was updated successfully, but these errors were encountered: