astoilkov / main-thread-scheduling

Fast and consistently responsive apps using a single function call
MIT License
1.29k stars 32 forks source link

Compile errors in v6.0.0 #7

Closed gregdingle closed 2 years ago

gregdingle commented 2 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch main-thread-scheduling@6.0.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/main-thread-scheduling/src/isTimeToYield.ts b/node_modules/main-thread-scheduling/src/isTimeToYield.ts
index f54e6a9..d827ae9 100644
--- a/node_modules/main-thread-scheduling/src/isTimeToYield.ts
+++ b/node_modules/main-thread-scheduling/src/isTimeToYield.ts
@@ -19,8 +19,10 @@ export default function isTimeToYield(priority: 'background' | 'user-visible'):
     }

     lastCallTime = now
+    // @ts-ignore: scheduling is new experimental API
+    const inputPending = navigator.scheduling?.isInputPending?.()
     lastResult =
-        now >= calculateDeadline(priority) || navigator.scheduling?.isInputPending?.() === true
+        now >= calculateDeadline(priority) || inputPending === true

     if (lastResult) {
         state.frameTimeElapsed = true
diff --git a/node_modules/main-thread-scheduling/src/tracking.ts b/node_modules/main-thread-scheduling/src/tracking.ts
index 033c536..14cf024 100644
--- a/node_modules/main-thread-scheduling/src/tracking.ts
+++ b/node_modules/main-thread-scheduling/src/tracking.ts
@@ -41,6 +41,7 @@ export function startTracking(): void {
                 isTracking = false

                 if (typeof cancelIdleCallback !== 'undefined') {
+                    // @ts-ignore: will be defined
                     cancelIdleCallback(idleCallbackId)
                 }
             } else {
diff --git a/node_modules/main-thread-scheduling/src/yieldControl.ts b/node_modules/main-thread-scheduling/src/yieldControl.ts
index 7236816..74a98b2 100644
--- a/node_modules/main-thread-scheduling/src/yieldControl.ts
+++ b/node_modules/main-thread-scheduling/src/yieldControl.ts
@@ -49,6 +49,7 @@ async function schedule(priority: 'user-visible' | 'background'): Promise<void>
         await new Promise<void>((resolve) => requestNextTask(resolve))

         // istanbul ignore if
+        // @ts-ignore: scheduling is new experimental API
         if (navigator.scheduling?.isInputPending?.() === true) {
             await schedule(priority)
         } else if (state.frameWorkStartTime === undefined) {

This issue body was partially generated by patch-package.

gregdingle commented 2 years ago

This might just be an issue on my end because I installed from github.com. If I install from npm, it works.

astoilkov commented 2 years ago

Yeah. When installing from GitHub you will get the TypeScript code, when installing from npm you will get compiled JavaScript code.

The repo has a /typings folder that has the additional typings (that were patched by patch-package). Probably your build system doesn't read the main-thread-scheduling tsconfig.json file in order to detect the folder.

In general, installing TypeScript repos from GitHub may be problematic because most of the time they don't include the compiled JavaScript.

I am closing this because the npm version works which is the official way of installing the library.