icambron / twix.js

:hourglass::left_right_arrow: A date range plugin for moment.js
https://isaaccambron.com/twix.js/
MIT License
379 stars 54 forks source link

Using twix in typescript #92

Closed rastographics closed 7 years ago

rastographics commented 7 years ago

Has anyone used twix with typescript and could share how you got it working? I have

import * as moment from 'moment';
import * as twix from 'twix';

Moment is working fine, intellisense and everything. Twix module imports fine and if I type twix. I can see the interface pop up.

But I get "Property twix does not exist on Moment" when I try to use moment(date).twix()

icambron commented 7 years ago

Linking to the matching SO post so other people can find it: http://stackoverflow.com/questions/39813233/how-do-you-use-twix-momentjs-with-typescript

dnmd commented 7 years ago

It seems that the given answer no longer works. Are there by any chance any updates on this topic? Regardless, thanks for the great library! :)

icambron commented 7 years ago

I'm unfortunately just not a TypeScript guy, so I don't know how to help. If you do find a solution, please post it here.

dnmd commented 7 years ago

Use the following to get things up and running with Angular 2+ or Ionic 2+:

import moment from "moment";
import "twix";

Hope this helps someone! It might be a good addition to: http://isaaccambron.com/twix.js/docs.html#getting-started

swavekl commented 3 years ago

I am using Typescript and Angular 10+ and after installing these versions of twix types, moment and twix. "@types/twix": "^0.6.38", "moment": "^2.29.1", "twix": "^1.3.0",

and importing them like this.

import * as moment from 'moment'; import 'twix';

and this works with Dates.

moment(startDate).twix(endDate, {allDay: true}).format();