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

ERROR in node_modules/dayjs/index.d.ts(99,30): error TS2304: Cannot find name 'unknown'. node_modules/dayjs/index.d.ts(101,30): error TS2304: Cannot find name 'unknown'. #928

Closed
abhiram90 opened this issue Jun 9, 2020 · 11 comments

Comments

@abhiram90
Copy link

abhiram90 commented Jun 9, 2020

Describe the bug

Used dayjs in angular component as below. Got error when buildng the application.

import * as dayjs from 'dayjs';
import * as utc from 'dayjs/plugin/utc';
dayjs.extend(utc);

component{
var x = dayjs.utc(initialDate).format('YYYY-MM-DD');
}

image

image

Information

  • Day.js Version [e.g. v1.8.28]
  • OS: [e.g. Windows]
  • Browser [e.g. chrome 78]
  • Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]
@iamkun
Copy link
Owner

iamkun commented Jun 10, 2020

Can you test this in a pure typescript project and check if the ts config is correct.

ref https://day.js.org/docs/en/installation/typescript

@abhiram90
Copy link
Author

Hi iamkun,
Please see Stackblitz for new error now in a pure typescript project.
pure typescript demo with dayjs

@felipesilvati
Copy link

@abhiram90 The unknown type was only introduced in typescript version > 3

You'll probably need to update your typescript to latest. I also had problems with @types/node, but only updating it to latest worked as well! I hope that fixes your issue too!

@felipesilvati
Copy link

@iamkun what do you think about adding some information in the readme that dayjs requires typescript version > 3?

@iamkun
Copy link
Owner

iamkun commented Jul 14, 2020

Sounds sweet!

@padunk
Copy link

padunk commented Oct 28, 2020

Hi,
I also have the same problem with React + TS project
dayjs: 1.9.4
TS: 3.7.2
OS: windows

import * as dayjs from "dayjs";
import * as relativeTime from "dayjs/plugin/relativeTime";

dayjs.extend(relativeTime);

It gives me this warning:

Argument of type '{ default: PluginFunc<RelativeTimeOptions>; }' is not assignable to parameter of type 'PluginFunc<unknown>'.
  Type '{ default: PluginFunc<RelativeTimeOptions>; }' provides no match for the signature '(option: unknown, c: typeof Dayjs, d: typeof import("f:/projects/fade-to-black/client/node_modules/dayjs/index.d.ts")): void'.

@iamkun
Copy link
Owner

iamkun commented Oct 28, 2020

@padunk a reproduction demo please

@padunk
Copy link

padunk commented Oct 28, 2020

@iamkun here is the link with vanilla TS in codesandbox

@iamkun
Copy link
Owner

iamkun commented Oct 28, 2020

@padunk According to your 'tsconfig', this should work fine.

import dayjs from "dayjs";
import isLeapYear from "dayjs/plugin/isLeapYear"; // import plugin
dayjs.extend(isLeapYear)

Ref: https://day.js.org/docs/en/installation/typescript#have-trouble-importing-dayjs

@padunk
Copy link

padunk commented Oct 28, 2020

@iamkun , sorry I just copy paste from the docs.
I think the way I import it was wrong.

import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";

dayjs.extend(relativeTime);

This work fine.

@iamkun
Copy link
Owner

iamkun commented Oct 28, 2020

A temp fix could be

declare global {
  type unknown = any
}

or to be more exact if you want:

export type mixed = { [key: string]: any } | object | number | string | boolean | symbol | undefined | null | void

declare global {
  type unknown = mixed
}

ref: getsentry/sentry-javascript#2322 (comment)

PS: We could replace this 'unknown' with some other syntax to make it work under typescript 3.

@iamkun iamkun closed this as completed Oct 28, 2020
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

4 participants