-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Property 'fromNow' does not exist on type 'Dayjs' #297
Comments
method |
@dmk1111 thanks for the reply. Just wondering if we should add plugin methods like |
@iamkun I suppose it better to keep them separate and than just import all of them to main file |
@iamkun Can you tell me, when you are gonna release the new patch version with this issue fix? |
@iamkun when can u fix this problem? Its almost a month now since I've created the issue? |
@yashwp you could introduce PR with desired fixes, in case you want those changes to appear faster |
@dmk1111 Bro I don't know how to work with... |
@yashwp in case you want to know how to create If you didn't manage to create it by yourself, I'll try to do this later, maybe in a week or so. |
This might help
|
@dmk1111 I tried to create Thank u :) |
You need at least one import statement to use Module Augmentation. import 'dayjs'
declare module 'dayjs' {
interface Dayjs {
... Also it seems you can nest module augmentation in declare module 'dayjs/plugin/relativeTime' {
module 'dayjs' {
... |
Also having issues with this... default installation of plugins does not work as described. |
So a temporary fix, until plugin typings are merged, is adding the following to your typings: // From: https://github.com/iamkun/dayjs/pull/418/files#diff-e5e546dd2eb0351f813d63d1b39dbc48
import { Dayjs, PluginFunc } from 'dayjs'
type DateType = string | number | Date | Dayjs
declare module 'dayjs' {
interface Dayjs {
fromNow(withoutSuffix?: boolean): string
from(compared: DateType, withoutSuffix?: boolean): string
toNow(withoutSuffix?: boolean): string
to(compared: DateType, withoutSuffix?: boolean): string
}
} |
🎉 This issue has been resolved in version 1.8.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hey @iamkun and @ypresto, thanks for your work! On
I guess this could be related to this issue, right? |
@wottpal Thanks for the feedback, that's my mistake. Fixed in v1.8.8. 😬 |
fixed, merged, released... 💯 How to use it now? 🔢 I am trying this : import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
console.log(dayjs.from(dayjs('1990'))); error : |
@stunaz dayjs version, please? And if in a TypeScript project, you could try |
v 1.8.9 see for yourself |
@stunaz I see. You should use |
indeed @iamkun ... thanks! |
This worked fine for me, in case anyone still needs it |
The problem was solved using the above answer, but the type error still occurs, so the type was declared to eliminate it. /@types/dayjs/index.d.ts
|
Still having this issue with version 1.11.0. This old post from 2019 solved it.
|
@designbyadrian there should be a type file shipped with 1.11.0 |
What does that mean? I'm having a similar issue with this. I don't have much experience with frontend and simply explaining what I need to do would be great. I'm currently using the temporary fix and sitting on version 1.11.0 |
try this:
|
Changing the way import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
dayjs.extend(relativeTime) |
Similarly, if not in a module (from @omerg's post), this worked for me: const dayjs = require('dayjs');
const relativeTime = require('dayjs/plugin/relativeTime');
dayjs.extend(relativeTime); |
We had a weird issue where the function was not available depending on how it was re-exported. This appears to be minification/tree-shaking related. We are using Rollup. This fixed it. import originalDayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat.js';
import calendar from 'dayjs/plugin/calendar.js';
import duration from 'dayjs/plugin/duration.js';
import isBetween from 'dayjs/plugin/isBetween.js';
import isToday from 'dayjs/plugin/isToday.js';
import isYesterday from 'dayjs/plugin/isYesterday.js';
import relativeTime from 'dayjs/plugin/relativeTime.js';
originalDayjs.extend(advancedFormat);
originalDayjs.extend(relativeTime);
originalDayjs.extend(duration);
originalDayjs.extend(calendar);
originalDayjs.extend(isYesterday);
originalDayjs.extend(isToday);
originalDayjs.extend(isBetween);
- export { default as dayjs } from 'dayjs';
+ export { originalDayjs as dayjs }; This only started happening after switching form commonjs to esm. |
dayjs version = 1.11.7
throws in js:
Two days later...
So I just changed
|
I'm using the
relativeTime
plugin in my.ts
fileImporting is done in below manner : -
import * as dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
I've also tried to change the import statement as:
import dayjs from 'dayjs';
But started throwing new error asno exported member
Now when I'm using in the
fromNow
function as: -dayjs(this.created_at).fromNow();
the compiler is throwing an errorProperty 'fromNow' does not exist on type 'Dayjs'
I'm using
"dayjs": "^1.7.4",
versionWhat's the with usage? How can I fix this?
@iamkun Please address this issue
The text was updated successfully, but these errors were encountered: