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

Build fails with Typescript version v4.4 #90

Open
apaar97 opened this issue Jun 27, 2022 · 1 comment
Open

Build fails with Typescript version v4.4 #90

apaar97 opened this issue Jun 27, 2022 · 1 comment

Comments

@apaar97
Copy link

apaar97 commented Jun 27, 2022

TS v4.4 brought in modifications to lib dom type defintions (reference).

These conflict with the types declared for requestIdleCallback and cancelIdleCallback on global window here:

declare global {
  const requestIdleCallback: (
    callback: (deadline: RequestIdleCallbackDeadline) => void,
    opts?: RequestIdleCallbackOptions,
  ) => RequestIdleCallbackHandle;
  const cancelIdleCallback: (handle: RequestIdleCallbackHandle) => void;

  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  interface Window {
    requestIdleCallback: typeof requestIdleCallback;
    cancelIdleCallback: typeof cancelIdleCallback;
  }
}

The above results in below errors during build:

node_modules/react-vtree/dist/es/utils.d.ts:16:11 - error TS2451: Cannot redeclare block-scoped variable 'requestIdleCallback'.
16     const requestIdleCallback: (callback: (deadline: RequestIdleCallbackDeadline) => void, opts?: RequestIdleCallbackOptions) => RequestIdleCallbackHandle;
             ~~~~~~~~~~~~~~~~~~~
  node_modules/typescript/lib/lib.dom.d.ts:17772:18
    17772 declare function requestIdleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): number;
                           ~~~~~~~~~~~~~~~~~~~
    'requestIdleCallback' was also declared here.

node_modules/react-vtree/dist/es/utils.d.ts:17:11 - error TS2451: Cannot redeclare block-scoped variable 'cancelIdleCallback'.
17     const cancelIdleCallback: (handle: RequestIdleCallbackHandle) => void;
             ~~~~~~~~~~~~~~~~~~
  node_modules/typescript/lib/lib.dom.d.ts:17741:18
    17741 declare function cancelIdleCallback(handle: number): void;
                           ~~~~~~~~~~~~~~~~~~
    'cancelIdleCallback' was also declared here.

I am unable to use later TS version because of this error, can we drop the redundant type declarations in favor of native support (I don't think upgrading TS version breaks anything within the library)?
Alternatively can someone suggest how can I override types here as a workaround?

@gregjoeval
Copy link

@apaar97,

You could use module augmentation to manually change the types in this lib to match the ones that you expect, or vice versa.

I am also using this library with [email protected] and don't have a problem running the typescript compiler. When I downgraded to [email protected] and had other issues than the one you described when I ran tsc, so I would suggest upgrading if you haven't already.

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

2 participants