1

The answers I currently see on the web are seemingly out-of-date.

I have node_modules/leaflet-draw and node_modules/@types/leaflet-draw installed.

This line works:

import * as L from 'leaflet';

However this line does not:

import * as foo from 'leaflet-draw';

I receive this error:

/node_modules/@types/leaflet-draw/index.d.ts' is not a module.

To add confusion, this line works:

var leafletDraw = require('leaflet-draw');

Can anyone help me make sense of this?

1 Answer 1

1

Looking at the source for @types/leaflet-draw and @types/leaflet, it appears that @types/leaflet is where the actual module declaration occurs:

declare module 'leaflet' {
    export = L;
}

while in @types/leaflet-draw, the namespace L is just extended (therefore adding all of its members to the original leaflet module).

Sign up to request clarification or add additional context in comments.

2 Comments

What would be the proper import statement in this situation?
I would go with import * as L from 'leaflet'; from a TypeScript perspective. Assuming leaflet and leaflet-draw are set up correctly, L should have all of the properties of leaflet-draw (as well as the ones of leaflet).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.