Skip to content

convert const enums to regular enums#1430

Open
avacreeth wants to merge 2 commits into
stagingfrom
remove_const_enums
Open

convert const enums to regular enums#1430
avacreeth wants to merge 2 commits into
stagingfrom
remove_const_enums

Conversation

@avacreeth
Copy link
Copy Markdown
Member

This package exports const enums instead of regular enums. References to a const enum are inlined at compile time, so there is no runtime object associated with the enum. Most modern javascript bundlers compile typescript with isolatedModules: true which means that type checking doesn't happen across module boundaries, and therefore the enums cannot be inlined.

Removing the const keyword from these enums means that the compiled javascript build object for module.ts will contain runtime objects that can be used to access enum values.

@summeroff summeroff force-pushed the remove_const_enums branch from 9af8599 to a6cfe98 Compare April 9, 2024 18:31
summeroff added a commit that referenced this pull request Jun 1, 2026
const enum members are inlined at compile time and produce no runtime
object. Downstream consumers that bundle with isolatedModules: true
cannot inline across module boundaries, so osn.E*.* reads resolve to
undefined at runtime. Dropping const makes tsc emit real runtime enum
objects into module.js.

Source change folded in from #1430 (Ava Creeth); the js/ outputs were
regenerated via the build:javascript pipeline. type_check.js now resolves
EPropertyType through the runtime object instead of inlined numeric
literals, demonstrating the same inlining fix in this repo's own code.

Co-authored-by: Ava Creeth <avacreeth@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@summeroff summeroff mentioned this pull request Jun 1, 2026
3 tasks
summeroff added a commit that referenced this pull request Jun 2, 2026
Restores `const enum` for all exported enums. The regular-enum conversion
(folded in from #1430) made the enum runtime objects live in module.js,
which broke the desktop webpack build: ~11 desktop files import enum
values directly from 'obs-studio-node' and relied on const-enum inlining
to keep them type-only. As regular enums those imports became runtime
value imports, pulling obs-studio-node/module.js (and its native
obs_studio_client.node require) into the renderer bundle, which has no
node-loader and does not externalize osn.

desktop never bundles osn (it loads it at runtime via window.require), so
#1430's "bundlers can't inline const enums" rationale does not apply to
the primary consumer. Keeping const enums.

The js/ build pipeline, generated-file CI check, API-drift fixes, and the
typing-accuracy fixes from PR review are unaffected and retained.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sandboxcoder sandboxcoder requested a review from Copilot June 3, 2026 17:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make exported enums available at runtime by converting const enum declarations to regular enums, addressing compatibility issues with toolchains that compile TypeScript using isolatedModules: true (where const enum inlining across module boundaries can’t be relied on).

Changes:

  • Converted many exported const enums in js/module.ts / js/module.d.ts to regular enums so they produce runtime objects.
  • Updated the compiled js/module.js to emit and export those runtime enums.
  • Updated js/type_check.js to reference EPropertyType.* enum members instead of numeric literals.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
js/type_check.js Switches comparisons from inlined numeric constants to EPropertyType enum members (now requiring ./module at runtime).
js/module.ts Converts a large set of exported const enums to runtime enums.
js/module.js Compiled output updated to include runtime enum objects and exports.
js/module.d.ts Updates enum declarations to match the runtime enums; also includes some additional type/value sync changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread js/module.ts
Comment on lines +33 to 36
export enum ESourceFlags {
Unbuffered = (1 << 0),
ForceMono = (1 << 1)
}
Comment thread js/type_check.js
Comment on lines 3 to +6
exports.isEmptyProperty = exports.isFontProperty = exports.isCaptureProperty = exports.isColorProperty = exports.isButtonProperty = exports.isBooleanProperty = exports.isEditableListProperty = exports.isListProperty = exports.isPathProperty = exports.isTextProperty = exports.isNumberProperty = void 0;
const obs = require("./module");
function isNumberProperty(property) {
return property.type === 2 ||
property.type === 3;
return property.type === obs.EPropertyType.Int ||
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

Successfully merging this pull request may close these issues.

2 participants