Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import in typescript file #148

Closed
berardo opened this issue Jul 4, 2016 · 9 comments
Closed

Import in typescript file #148

berardo opened this issue Jul 4, 2016 · 9 comments

Comments

@berardo
Copy link

berardo commented Jul 4, 2016

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'.

@BristolNET
Copy link

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

@BristolNET
Copy link

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.

@marchagele
Copy link

marchagele commented Sep 3, 2016

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!

@dennis2k
Copy link

dennis2k commented May 8, 2017

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

@uncledent
Copy link

@dennis2k and how have you solved it with rrulestr?

@dennis2k
Copy link

@uncledent I was only able to this using require

var rrulestr = require('rrule').rrulestr

@uncledent
Copy link

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

@uncledent
Copy link

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

@arolson101
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants