-
Notifications
You must be signed in to change notification settings - Fork 121
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
Typescript support #106
Comments
Either
|
I haven't done that much in Typescript before, does anyone have any experience with this that can point me in the right direction? |
@nomadoda you can't use intellisense yet, since there are not typings for this project. You can, however, still use it together with typescript. @BrockReece you need to provide some typescript typings for that. Maybe this helps: https://www.triplet.fi/blog/three-ways-to-provide-typescript-type-definitions-to-3rd-party-libraries/ |
This is kind of old but it's still open. I'm actually here for something else but I worked around lack of @types package by creating vue-moment.d.ts in a /types directory. It contains the following:
And then in main.ts
|
I fixed typings by creating a d.ts file with the following contents:
|
Based on @demianh script, I made some changes, because it doesn't work using With below this.$moment
.duration(5, "minutes")
.timer({ start: true }, callback);
const tokensExpiry = this.$moment().add(data.expires_in, 's').toISOString(); // @types/vue.d.ts
import * as moment from "moment";
interface ITimerAttr {
wait?: number;
loop?: boolean;
start?: boolean;
}
interface Callback {
(): void;
}
interface Timer {
start(): boolean;
stop(): boolean;
clearTime(): boolean;
updateStartEndTickFromDuration(duration: number): boolean;
getDuration(): number;
getRemainingDuration(): number;
isStopped(): boolean;
isStarted(): boolean;
}
interface IMoment extends moment.Moment, Timer {
(
inp?: moment.MomentInput,
format?: moment.MomentFormatSpecification,
language?: string,
strict?: boolean
): IMoment;
duration(
inp?: moment.DurationInputArg1,
unit?: moment.DurationInputArg2
): IMoment;
timer(attributes: ITimerAttr, callback?: Callback): IMoment;
}
declare module "vue/types/vue" {
interface Vue {
$moment: IMoment;
}
interface VueConstructor {
$moment: IMoment;
}
} |
I think this works too given that the Type declarations:
|
Perfect! Thanks guys! |
I'm not sure how I would import the
Moment
type through this package. Would I need to also include the momentjs dependency for types in my project?The text was updated successfully, but these errors were encountered: