@types/zepto prevents me from importing zepto itself

502 Views Asked by At

I have installed zepto and @types/zepto packages in npm. If I install only zepto without types and import it like this:

import * as $ from 'zepto';

Everything works. But if I install @types/zepto as well, it's presence in the node_modules directory somehow breaks it. It says "@types/zepto/index.d.ts is not module". How do I load type definitions for Zepto?

2

There are 2 best solutions below

0
Dragomir Kolev On

This is probably worth a read for you. It will explain how type files work.

If you put this fine in your types folder in your project it should work just fine.

0
Alex Fang On

@types/jquery: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jquery/index.d.ts

@types/zepto: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/zepto/index.d.ts

In @types/jquery, it writes export = jQuery, while in @types/zepto, it only writes declare var Zepto and declare var $.

These are different.

export can be imported as modules, but declare var declare global stuff, thus you should not use anything like import * as $ from 'zepto' or import $ from 'zepto'. The Zepto and $ are declared globally if you have @types/zepto installed.