{"id":26473,"library":"threadedclass","title":"threadedClass","description":"Fork a class instance into a separate thread (Node.js Worker Threads or Web Workers) while preserving TypeScript typings. v1.4.0 is stable with a mature API. Key differentiators: one-liner thread instantiation, automatic method promisification, optional auto-restart on crash, and thread pooling via ThreadedClassManager. Actively maintained with frequent releases, supports Node ≥8 and modern browsers.","status":"active","version":"1.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/nytamin/threadedClass","tags":["javascript","thread","async","fork","asynchronous","typescript"],"install":[{"cmd":"npm install threadedclass","lang":"bash","label":"npm"},{"cmd":"yarn add threadedclass","lang":"bash","label":"yarn"},{"cmd":"pnpm add threadedclass","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export does not exist; always use named import.","wrong":"import threadedClass from 'threadedclass'","symbol":"threadedClass","correct":"import { threadedClass } from 'threadedclass'"},{"note":"Named import in ESM. In CJS, use const { ThreadedClassManager } = require('threadedclass').","wrong":"const ThreadedClassManager = require('threadedclass').ThreadedClassManager","symbol":"ThreadedClassManager","correct":"import { ThreadedClassManager } from 'threadedclass'"},{"note":"TypeScript consumers can import the config type for type safety. Not available at runtime.","wrong":null,"symbol":"ThreadedClassConfig","correct":"import type { ThreadedClassConfig } from 'threadedclass'"}],"quickstart":{"code":"import { threadedClass } from 'threadedclass';\n\n// Assume ./professor.ts exports class Professor with methods like talkAboutAncientGreece()\nconst mrSmith = await threadedClass<Professor>(\n  './professor.js', // path to compiled JS file\n  'Professor',\n  ['maths', 'greek'], // constructor args\n  { autoRestart: true } // optional config\n);\n\n// All methods return promises\nconst story = await mrSmith.talkAboutAncientGreece();\nconsole.log(story);","lang":"typescript","description":"Creates a forked instance of Professor class running in a separate thread. Constructor arguments are passed as array; all methods become async."},"warnings":[{"fix":"Use the compiled output path (e.g., './professor.js').","message":"The module path must point to the compiled JavaScript file, not the TypeScript source. Using .ts will cause runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `ThreadedClassManager.setThreadUsage(0.1)` instead of passing `threadUsage` in config.","message":"The `threadUsage` option is deprecated. Use `ThreadedClassManager.setThreadUsage()` for thread pool control.","severity":"deprecated","affected_versions":">=1.2.0"},{"fix":"Add `await` before calling `threadedClass()`.","message":"In v1.0.0, the `threadedClass` function returned the instance directly (sync). Since v1.1.0 it returns a Promise, breaking old code that did not use await.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Convert properties to getter methods (e.g., `getName()` instead of `name`).","message":"Properties of the class are not accessible on the forked instance: only methods are promisified. Accessing a property returns `undefined`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set config option `pathToWorker: 'lib/threadedclass-worker.js'`.","message":"In browser environments, you must provide `pathToWorker` in the config, otherwise the worker script won't be found.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `import { threadedClass } from 'threadedclass'` or `const { threadedClass } = require('threadedclass')`.","cause":"Default import used instead of named import.","error":"TypeError: threadedClass is not a function"},{"fix":"Ensure the path points to the .js file after compilation (e.g., ./professor.js). Compile TypeScript first.","cause":"The compiled JS file path is incorrect or the module is not yet compiled.","error":"Cannot find module './professor.js'"},{"fix":"Use the second argument as a string: `threadedClass('./professor.js', 'Professor', ...)`. In browser, you must pass the class reference.","cause":"Passing the class object directly instead of the export name string in Node.js.","error":"Error: Class constructor must be invoked with 'new'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}