I have the following definition type file:
// index.d.ts
declare module 'Transformer' {
class EditableElement {
constructor(target: SVGPoint);
}
export = EditableElement;
}
And I want to import EditableElement
. But when I write the following line:
import {EditableElement} from 'Transformer';
I get the next error:
Module "Transformer" resolves to a non-module entity and cannot be imported using this construct.
How could I import the EditableElement
class? Actually, I just want to make use of that class. I don't want the import
directive to have a collateral effect in my code. I just want use it :'(
This falls into ES6 / CommonJS interop.
My recommendation is to not relying on interop and use the old syntax instead:
const EditableElement = require('Transformer')
If you NEED to target es6/es2015, then you can do:
import * as EditableElement from 'Transformer'
// with `allowSyntheticDefaultImports`
import EditableElement from 'Transformer'
UPDATE: with [email protected] released, you can now do import EditableElement from 'Transformer'
directly.
Turn on esModuleInterop
in your tsconfig.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With