Typings
From version 4.2.0
Mobiscroll for JQuery comes with type definitions files, that allow better usage in typescript environments.
Installing types
Type definition files come with the extension *.d.ts
and are included in every Mobiscroll package from version 4.2.0
. Installing and importing the mobiscroll package makes the types available as well.
Example installing and using the types with npm:
$ mobiscroll config jquery --version=4
After installation the package needs to be imported into the app with the needed types:
import '@mobiscroll/jquery'; // importing the mobiscroll package
import { Calendar, MbscCalendarOptions } from '@mobiscroll/jquery'; // importing types
Usage
// declaring the options with the type gives auto-suggest for settings
var options: MbscCalendarOptions = {
theme: 'ios',
calendarScroll: 'vertical'
};
// Initializing the calendar
var myInput = $('#myID').mobiscroll().calendar(options);
// Getting the reference of the instance
var calendarInstance: Calendar = myInput.mobiscroll('getInst') as Calendar;
// Calling instance methods
calendarInstance.setVal(new Date(), true, false);
calendarInstance.show();