Rrule: Import in typescript file

Created on 4 Jul 2016  ·  9Comments  ·  Source: jakubroztocil/rrule

Hey guys,
I was wondering how can I import rrule.js file from typescript:
import 'rrule';
Doesn't seem to work because module.exports is evaluated true, so even the global scope is not populated.
When I try any other kind of import like:
import * as rrule from 'rrule';
I get this when compiling:
Error TS2307: Cannot find module 'rrule'.

Most helpful comment

Running npm install @types/rrule solved the issue for me. I was then able to import like this
import { RRule, RRuleSet } from "rrule";

All 9 comments

I'm having the same issue. Ever find a fix?

See this example:

http://jqfaq.com/how-to-use-external-js-in-typescript/

I was able to use RRule in my ts file like so (after including rrule.js in my index.html page):

// File form.ts
declare var RRule: any;

module myapp.controllers {

class myClass {
    constructor() {
        var rule = RRule.fromString('FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13');
        console.log(rule.toText());
    }
}

}

Hope this helps someone.

What I do in this cases is to define a Typing.
Add a file to typings -> rrule.d.ts

content of the rrule.d.ts file:

declare var RRule: any; declare var RRuleSet: any; declare var rrulestr: any;

you can extend their properties there if you want.

then link the rrule.d.ts to index.d.ts per example (i normally group all my d.ts in 1 file referencing them there)

index.d.ts:
/// <reference path="globals/rrule/rrule.d.ts" />

after that you can use

RRule.fromString('FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13');

without defining the
declare var RRule: any;
everywhere again.

Best regards!

Running npm install @types/rrule solved the issue for me. I was then able to import like this
import { RRule, RRuleSet } from "rrule";

@dennis2k and how have you solved it with rrulestr?

@uncledent I was only able to this using require

var rrulestr = require('rrule').rrulestr

@dennis2k Thank you for your answer, but this can't be used in Angular4 :(

I could do this this way in Angular2/4, not pretty, but works:
declare function require(name:string); var rrulestr = require('rrule').rrulestr;

I think this issue is dead. Please update if more support is needed!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elazar picture elazar  ·  18Comments

espen picture espen  ·  11Comments

anthwinter picture anthwinter  ·  11Comments

espen picture espen  ·  10Comments

agordeev picture agordeev  ·  16Comments