Similar to https://github.com/Microsoft/TypeScript/issues/2929
Using released TS 1.5.3,
Trying to type-check the ES6 emit for angular, I run into:
angular2/typings/node/node.d.ts (273, 5): Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead.
Because of syntax here:
https://github.com/borisyankov/DefinitelyTyped/blob/983126e131a2b81739053d60e4bbdbb46d6577b7/node/node.d.ts#L425
Can this rule be relaxed? Do all typings need to be updated?
https://gist.github.com/robertpenner/7d48f184df1236c4fdca is a workaround.
Thanks @robertpenner
The error is there as there is no valid ES6 construct that maps to the export= semantics; so we do not know how to emit it. However, we could relax the constraint for ambient module declarations as there is no code emit impact.
In case this is helpful for anyone, I ended up using this bit of hack in my setup script to rewrite imports:
for file in DefinitelyTyped/*/*.ts ; do
sed -i "s@import *\(.*\)= *require(\([\"'].*[\"']))@import * as \1from \2@g" "$file";
done
@mhegazy I am getting the error when using the below code in typescript. I used the guide here - https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html
declare function require(path: string): any;
import googleMaps = require('@google/maps');
Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from
"mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
L9: declare function require(path: string): any;
L10: import googleMaps = require('@google/maps');
Cannot find module '@google/maps'.
L9: declare function require(path: string): any;
L10: import googleMaps = require('@google/maps');
tsconfig.json
"module": "es2015",
"moduleResolution": "node",
"target": "es5"
Use var instead of import
Thank you. It worked! :)
On Wed, Dec 7, 2016 at 9:16 PM, Mohamed Hegazy notifications@github.com
wrote:
Use var instead of import
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/TypeScript/issues/4170#issuecomment-265649037,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AP-IYbLqeHAz5H_cQ-MUeR8nm8yKUtIAks5rF4S0gaJpZM4Fma9v
.
Most helpful comment
Use var instead of import